diff --git a/v3/src/animation/manager/AnimationManager.js b/v3/src/animation/manager/AnimationManager.js index ceee72329..6a3d30139 100644 --- a/v3/src/animation/manager/AnimationManager.js +++ b/v3/src/animation/manager/AnimationManager.js @@ -15,7 +15,7 @@ var Map = require('../../structs/Map'); * * Sprites and other Game Objects get the data they need from the AnimationManager. * -* Access it via `state.anims`. +* Access it via `scene.anims`. * * @class Phaser.AnimationManager * @constructor diff --git a/v3/src/boot/Config.js b/v3/src/boot/Config.js index ce050035d..8c5c17079 100644 --- a/v3/src/boot/Config.js +++ b/v3/src/boot/Config.js @@ -41,7 +41,7 @@ var Config = new Class({ this.canvas = GetValue(config, 'canvas', null); this.canvasStyle = GetValue(config, 'canvasStyle', null); - this.stateConfig = GetValue(config, 'state', null); + this.sceneConfig = GetValue(config, 'scene', null); this.seed = GetValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]); diff --git a/v3/src/boot/Game.js b/v3/src/boot/Game.js index 4f01ba12e..733587468 100644 --- a/v3/src/boot/Game.js +++ b/v3/src/boot/Game.js @@ -14,7 +14,7 @@ var CreateRenderer = require('./CreateRenderer'); var Data = require('../plugins/Data'); var GlobalCache = require('../cache/GlobalCache'); var GlobalInputManager = require('../input/GlobalInputManager'); -var GlobalStateManager = require('../state/GlobalStateManager'); +var GlobalSceneManager = require('../scene/GlobalSceneManager'); var TextureManager = require('../textures/TextureManager'); var TimeStep = require('./TimeStep'); @@ -64,9 +64,9 @@ var Game = new Class({ this.input = new GlobalInputManager(this, this.config); /** - * @property {Phaser.GlobalStateManager} state - The StateManager. Phaser instance specific. + * @property {Phaser.GlobalSceneManager} scene - The SceneManager. Phaser instance specific. */ - this.state = new GlobalStateManager(this, this.config.stateConfig); + this.scene = new GlobalSceneManager(this, this.config.sceneConfig); /** * @property {Phaser.Device} device - Contains device information and capabilities (singleton) @@ -100,7 +100,7 @@ var Game = new Class({ this.anims.boot(this.textures); - this.state.boot(); + this.scene.boot(); this.input.boot(); @@ -120,18 +120,18 @@ var Game = new Class({ step: function (time, delta) { - var active = this.state.active; + var active = this.scene.active; var renderer = this.renderer; // Global Managers (Time, Input, etc) this.input.update(time, delta); - // States + // Scenes for (var i = 0; i < active.length; i++) { - active[i].state.sys.step(time, delta); + active[i].scene.sys.step(time, delta); } // Render @@ -140,10 +140,10 @@ var Game = new Class({ renderer.preRender(); - // This uses active.length, in case state.update removed the state from the active list + // This uses active.length, in case scene.update removed the scene from the active list for (i = 0; i < active.length; i++) { - active[i].state.sys.render(0, renderer); + active[i].scene.sys.render(0, renderer); } renderer.postRender(); @@ -153,11 +153,11 @@ var Game = new Class({ { this.loop.pause(); - // var active = this.state.active; + // var active = this.scene.active; // for (var i = 0; i < active.length; i++) // { - // active[i].state.sys.pause(); + // active[i].scene.sys.pause(); // } }, @@ -165,11 +165,11 @@ var Game = new Class({ { this.loop.resume(); - // var active = this.state.active; + // var active = this.scene.active; // for (var i = 0; i < active.length; i++) // { - // active[i].state.sys.resume(); + // active[i].scene.sys.resume(); // } }, diff --git a/v3/src/camera/Camera.js b/v3/src/camera/Camera.js index f07550d9a..fd3dcf11e 100644 --- a/v3/src/camera/Camera.js +++ b/v3/src/camera/Camera.js @@ -171,9 +171,9 @@ var Camera = new Class({ return this; }, - setState: function (state) + setScene: function (scene) { - this.state = state; + this.scene = scene; return this; }, @@ -477,7 +477,7 @@ var Camera = new Class({ destroy: function () { - this.state = undefined; + this.scene = undefined; } }); diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 5d751b45b..d04554828 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '8d1f7160-682b-11e7-b9b9-afea77e03fb0' +build: 'de3f9290-689a-11e7-813e-ffb54ad43616' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/gameobjects/BuildGameObject.js b/v3/src/gameobjects/BuildGameObject.js index 8966bcd3a..9a0aedb01 100644 --- a/v3/src/gameobjects/BuildGameObject.js +++ b/v3/src/gameobjects/BuildGameObject.js @@ -2,7 +2,7 @@ var GetAdvancedValue = require('../utils/object/GetAdvancedValue'); var ScaleModes = require('../renderer/ScaleModes'); var BlendModes = require('../renderer/BlendModes'); -var BuildGameObject = function (state, gameObject, config) +var BuildGameObject = function (scene, gameObject, config) { // Position @@ -89,13 +89,13 @@ var BuildGameObject = function (state, gameObject, config) gameObject.visible = GetAdvancedValue(config, 'visible', true); - // Add to State + // Add to Scene var add = GetAdvancedValue(config, 'add', true); if (add) { - state.children.add(gameObject); + scene.sys.displayList.add(gameObject); } return gameObject; diff --git a/v3/src/gameobjects/GameObject.js b/v3/src/gameobjects/GameObject.js index 355007d0a..71bf487ca 100644 --- a/v3/src/gameobjects/GameObject.js +++ b/v3/src/gameobjects/GameObject.js @@ -17,9 +17,9 @@ var GameObject = new Class({ initialize: - function GameObject (state, type) + function GameObject (scene, type) { - this.state = state; + this.scene = scene; this.type = type; @@ -39,8 +39,8 @@ var GameObject = new Class({ this.hitArea = null; this.hitAreaCallback = null; - // Trigger a state z-depth sort - this.state.sys.sortChildrenFlag = true; + // Trigger a scene z-depth sort + this.scene.sys.sortChildrenFlag = true; }, // For GameObject Pooling and item selection @@ -58,7 +58,7 @@ var GameObject = new Class({ setHitArea: function (shape, callback) { - this.state.sys.inputManager.setHitArea(this, shape, callback); + this.scene.sys.inputManager.setHitArea(this, shape, callback); return this; }, @@ -73,7 +73,7 @@ var GameObject = new Class({ { this.parent.remove(this); - this.state = undefined; + this.scene = undefined; } }); diff --git a/v3/src/gameobjects/bitmaptext/ParseFromAtlas.js b/v3/src/gameobjects/bitmaptext/ParseFromAtlas.js index 6dc547261..1d15d261a 100644 --- a/v3/src/gameobjects/bitmaptext/ParseFromAtlas.js +++ b/v3/src/gameobjects/bitmaptext/ParseFromAtlas.js @@ -1,15 +1,15 @@ var ParseXMLBitmapFont = require('./ParseXMLBitmapFont'); -var ParseFromAtlas = function (state, fontName, textureKey, frameKey, xmlKey, xSpacing, ySpacing) +var ParseFromAtlas = function (scene, fontName, textureKey, frameKey, xmlKey, xSpacing, ySpacing) { - var frame = state.sys.textures.getFrame(textureKey, frameKey); - var xml = state.sys.cache.xml.get(xmlKey); + var frame = scene.sys.textures.getFrame(textureKey, frameKey); + var xml = scene.sys.cache.xml.get(xmlKey); if (frame && xml) { var data = ParseXMLBitmapFont(xml, xSpacing, ySpacing, frame); - state.sys.cache.bitmapFont.add(fontName, { data: data, texture: textureKey, frame: frameKey }); + scene.sys.cache.bitmapFont.add(fontName, { data: data, texture: textureKey, frame: frameKey }); return true; } diff --git a/v3/src/gameobjects/bitmaptext/ParseRetroFont.js b/v3/src/gameobjects/bitmaptext/ParseRetroFont.js index cdff3e3c8..c72518a73 100644 --- a/v3/src/gameobjects/bitmaptext/ParseRetroFont.js +++ b/v3/src/gameobjects/bitmaptext/ParseRetroFont.js @@ -11,7 +11,7 @@ var GetValue = require('../../utils/object/GetValue'); // Phaser.GameObject.RetroFont = function (game, key, characterWidth, characterHeight, chars, charsPerRow, xSpacing, ySpacing, xOffset, yOffset) // { -// image: key, +// image: key, // width: 32, // height: 32, // chars: 'string', @@ -20,7 +20,7 @@ var GetValue = require('../../utils/object/GetValue'); // offset: { x: 0, y: 0 } // } -var ParseRetroFont = function (state, config) +var ParseRetroFont = function (scene, config) { var w = config.width; var h = config.height; @@ -38,7 +38,7 @@ var ParseRetroFont = function (state, config) if (charsPerRow === null) { - charsPerRow = state.sys.textures.getFrame(key).width / w; + charsPerRow = scene.sys.textures.getFrame(key).width / w; if (charsPerRow > letters.length) { diff --git a/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js b/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js index 72578719d..73f0e25bf 100644 --- a/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js +++ b/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js @@ -22,14 +22,14 @@ var DynamicBitmapText = new Class({ initialize: - function DynamicBitmapText (state, x, y, font, text, size, align) + function DynamicBitmapText (scene, x, y, font, text, size, align) { if (text === undefined) { text = ''; } if (align === undefined) { align = 'left'; } - GameObject.call(this, state, 'DynamicBitmapText'); + GameObject.call(this, scene, 'DynamicBitmapText'); - this.fontData = this.state.sys.cache.bitmapFont.get(font); + this.fontData = this.scene.sys.cache.bitmapFont.get(font); this.text = (Array.isArray(text)) ? text.join('\n') : text; diff --git a/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCreator.js b/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCreator.js index 24be11c0e..537ee8412 100644 --- a/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCreator.js +++ b/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextCreator.js @@ -2,16 +2,16 @@ var BitmapText = require('./DynamicBitmapText'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); var BuildGameObject = require('../../BuildGameObject'); -var DynamicBitmapTextCreator = function (state, config) +var DynamicBitmapTextCreator = function (scene, config) { var font = GetAdvancedValue(config, 'font', ''); var text = GetAdvancedValue(config, 'text', ''); var size = GetAdvancedValue(config, 'size', false); var align = GetAdvancedValue(config, 'align', 'left'); - var bitmapText = new BitmapText(state, 0, 0, font, text, size, align); + var bitmapText = new BitmapText(scene, 0, 0, font, text, size, align); - BuildGameObject(state, bitmapText, config); + BuildGameObject(scene, bitmapText, config); return bitmapText; }; diff --git a/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js b/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js index f097da2cb..476117921 100644 --- a/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js +++ b/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js @@ -1,8 +1,8 @@ var BitmapText = require('./DynamicBitmapText'); -var DynamicBitmapTextFactory = function (state, x, y, font, text, size, align) +var DynamicBitmapTextFactory = function (scene, x, y, font, text, size, align) { - return new BitmapText(state, x, y, font, text, size, align); + return new BitmapText(scene, x, y, font, text, size, align); }; module.exports = DynamicBitmapTextFactory; diff --git a/v3/src/gameobjects/bitmaptext/static/BitmapText.js b/v3/src/gameobjects/bitmaptext/static/BitmapText.js index 60c284444..bc2f5711a 100644 --- a/v3/src/gameobjects/bitmaptext/static/BitmapText.js +++ b/v3/src/gameobjects/bitmaptext/static/BitmapText.js @@ -25,15 +25,15 @@ var BitmapText = new Class({ initialize: - function BitmapText (state, x, y, font, text, size) + function BitmapText (scene, x, y, font, text, size) { if (text === undefined) { text = ''; } - GameObject.call(this, state, 'BitmapText'); + GameObject.call(this, scene, 'BitmapText'); this.font = font; - var entry = this.state.sys.cache.bitmapFont.get(font); + var entry = this.scene.sys.cache.bitmapFont.get(font); this.fontData = entry.data; diff --git a/v3/src/gameobjects/bitmaptext/static/BitmapTextCreator.js b/v3/src/gameobjects/bitmaptext/static/BitmapTextCreator.js index 2d66ae86a..184b9f80e 100644 --- a/v3/src/gameobjects/bitmaptext/static/BitmapTextCreator.js +++ b/v3/src/gameobjects/bitmaptext/static/BitmapTextCreator.js @@ -3,16 +3,16 @@ var BuildGameObject = require('../../BuildGameObject'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); var GetValue = require('../../../utils/object/GetValue'); -var BitmapTextCreator = function (state, config) +var BitmapTextCreator = function (scene, config) { var font = GetValue(config, 'font', ''); var text = GetAdvancedValue(config, 'text', ''); var size = GetAdvancedValue(config, 'size', false); - var align = GetValue(config, 'align', 'left'); + // var align = GetValue(config, 'align', 'left'); - var bitmapText = new BitmapText(state, 0, 0, font, text, size); + var bitmapText = new BitmapText(scene, 0, 0, font, text, size); - BuildGameObject(state, bitmapText, config); + BuildGameObject(scene, bitmapText, config); return bitmapText; }; diff --git a/v3/src/gameobjects/bitmaptext/static/BitmapTextFactory.js b/v3/src/gameobjects/bitmaptext/static/BitmapTextFactory.js index 756bca68b..7b6e406a0 100644 --- a/v3/src/gameobjects/bitmaptext/static/BitmapTextFactory.js +++ b/v3/src/gameobjects/bitmaptext/static/BitmapTextFactory.js @@ -1,8 +1,8 @@ var BitmapText = require('./BitmapText'); -var BitmapTextFactory = function (state, x, y, font, text, size) +var BitmapTextFactory = function (scene, x, y, font, text, size) { - return new BitmapText(state, x, y, font, text, size); + return new BitmapText(scene, x, y, font, text, size); }; module.exports = BitmapTextFactory; diff --git a/v3/src/gameobjects/blitter/Blitter.js b/v3/src/gameobjects/blitter/Blitter.js index 4a128d4ef..cb755710c 100644 --- a/v3/src/gameobjects/blitter/Blitter.js +++ b/v3/src/gameobjects/blitter/Blitter.js @@ -43,9 +43,9 @@ var Blitter = new Class({ initialize: - function Blitter (state, x, y, texture, frame) + function Blitter (scene, x, y, texture, frame) { - GameObject.call(this, state, 'Blitter'); + GameObject.call(this, scene, 'Blitter'); this.setTexture(texture, frame); this.setPosition(x, y); diff --git a/v3/src/gameobjects/blitter/BlitterCreator.js b/v3/src/gameobjects/blitter/BlitterCreator.js index 9a91f7d6a..95f16f94b 100644 --- a/v3/src/gameobjects/blitter/BlitterCreator.js +++ b/v3/src/gameobjects/blitter/BlitterCreator.js @@ -2,14 +2,14 @@ var Blitter = require('./Blitter'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var BuildGameObject = require('../BuildGameObject'); -var BlitterCreator = function (state, config) +var BlitterCreator = function (scene, config) { var key = GetAdvancedValue(config, 'key', null); var frame = GetAdvancedValue(config, 'frame', null); - var blitter = new Blitter(state, 0, 0, key, frame); + var blitter = new Blitter(scene, 0, 0, key, frame); - BuildGameObject(state, blitter, config); + BuildGameObject(scene, blitter, config); return blitter; }; diff --git a/v3/src/gameobjects/blitter/BlitterFactory.js b/v3/src/gameobjects/blitter/BlitterFactory.js index 2bbfbb0bc..34aae56e8 100644 --- a/v3/src/gameobjects/blitter/BlitterFactory.js +++ b/v3/src/gameobjects/blitter/BlitterFactory.js @@ -1,8 +1,8 @@ var Blitter = require('./Blitter'); -var BlitterFactory = function (state, x, y, key, frame) +var BlitterFactory = function (scene, x, y, key, frame) { - return new Blitter(state, x, y, key, frame); + return new Blitter(scene, x, y, key, frame); }; module.exports = BlitterFactory; diff --git a/v3/src/gameobjects/components/Animation.js b/v3/src/gameobjects/components/Animation.js index bc76ded65..57470b142 100644 --- a/v3/src/gameobjects/components/Animation.js +++ b/v3/src/gameobjects/components/Animation.js @@ -13,7 +13,7 @@ var Animation = new Class({ // Sprite / Game Object this.parent = parent; - this.animationManager = parent.state.sys.anims; + this.animationManager = parent.scene.sys.anims; this.animationManager.events.once('REMOVE_ANIMATION_EVENT', this.remove.bind(this)); diff --git a/v3/src/gameobjects/components/Texture.js b/v3/src/gameobjects/components/Texture.js index b05ac4eaa..51edb0f7b 100644 --- a/v3/src/gameobjects/components/Texture.js +++ b/v3/src/gameobjects/components/Texture.js @@ -10,7 +10,7 @@ var Texture = { setTexture: function (key, frame) { - this.texture = this.state.sys.textures.get(key); + this.texture = this.scene.sys.textures.get(key); this.frame = this.texture.get(frame); diff --git a/v3/src/gameobjects/components/Transform.js b/v3/src/gameobjects/components/Transform.js index cbc794bc0..234ec9e66 100644 --- a/v3/src/gameobjects/components/Transform.js +++ b/v3/src/gameobjects/components/Transform.js @@ -29,7 +29,7 @@ var Transform = { set: function (value) { - this.state.sys.sortChildrenFlag = true; + this.scene.sys.sortChildrenFlag = true; this._z = value; } diff --git a/v3/src/gameobjects/effectlayer/EffectLayer.js b/v3/src/gameobjects/effectlayer/EffectLayer.js index 035ce7f2e..febe0b6ea 100644 --- a/v3/src/gameobjects/effectlayer/EffectLayer.js +++ b/v3/src/gameobjects/effectlayer/EffectLayer.js @@ -29,12 +29,12 @@ var EffectLayer = new Class({ initialize: - function EffectLayer (state, x, y, width, height, effectName, fragmentShader) + function EffectLayer (scene, x, y, width, height, effectName, fragmentShader) { - GameObject.call(this, state, 'EffectLayer'); + GameObject.call(this, scene, 'EffectLayer'); var pot = ((width & (width - 1)) == 0 && (height & (height - 1)) == 0); - var resourceManager = state.game.renderer.resourceManager; + var resourceManager = scene.game.renderer.resourceManager; var wrap; var gl; @@ -45,7 +45,7 @@ var EffectLayer = new Class({ if (resourceManager !== undefined) { - gl = state.game.renderer.gl; + gl = scene.game.renderer.gl; wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE; this.dstShader = resourceManager.createShader(effectName, { vert: TexturedAndNormalizedTintedShader.vert, @@ -61,7 +61,7 @@ var EffectLayer = new Class({ ); this.dstRenderTarget = resourceManager.createRenderTarget(width, height, this.renderTexture, null); - state.game.renderer.currentTexture = null; // force rebinding of prev texture + scene.game.renderer.currentTexture = null; // force rebinding of prev texture } this.flipY = true; diff --git a/v3/src/gameobjects/effectlayer/EffectLayerCreator.js b/v3/src/gameobjects/effectlayer/EffectLayerCreator.js index e0c1aca92..2feb15237 100644 --- a/v3/src/gameobjects/effectlayer/EffectLayerCreator.js +++ b/v3/src/gameobjects/effectlayer/EffectLayerCreator.js @@ -2,7 +2,7 @@ var EffectLayer = require('./EffectLayer'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var BuildGameObject = require('../BuildGameObject'); -var EffectLayerCreator = function (state, config) +var EffectLayerCreator = function (scene, config) { var x = GetAdvancedValue(config, 'x', 0); var y = GetAdvancedValue(config, 'y', 0); @@ -11,9 +11,9 @@ var EffectLayerCreator = function (state, config) var key = GetAdvancedValue(config, 'key', null); var fragmentShader = GetAdvancedValue(config, 'fragmentShader', ''); - var layer = new EffectLayer(state, x, y, width, height, effectName, fragmentShader); + var layer = new EffectLayer(scene, x, y, width, height, effectName, fragmentShader); - BuildGameObject(state, layer, config); + BuildGameObject(scene, layer, config); return layer; }; diff --git a/v3/src/gameobjects/effectlayer/EffectLayerFactory.js b/v3/src/gameobjects/effectlayer/EffectLayerFactory.js index 8af17f822..0ce65c736 100644 --- a/v3/src/gameobjects/effectlayer/EffectLayerFactory.js +++ b/v3/src/gameobjects/effectlayer/EffectLayerFactory.js @@ -1,8 +1,8 @@ var EffectLayer = require('./EffectLayer'); -var EffectLayerFactory = function (state, x, y, width, height, effectName, fragmentShader) +var EffectLayerFactory = function (scene, x, y, width, height, effectName, fragmentShader) { - return new EffectLayer(state, x, y, width, height, effectName, fragmentShader); + return new EffectLayer(scene, x, y, width, height, effectName, fragmentShader); }; module.exports = EffectLayerFactory; diff --git a/v3/src/gameobjects/graphics/Graphics.js b/v3/src/gameobjects/graphics/Graphics.js index ae427b0f7..677937035 100644 --- a/v3/src/gameobjects/graphics/Graphics.js +++ b/v3/src/gameobjects/graphics/Graphics.js @@ -24,12 +24,12 @@ var Graphics = new Class({ initialize: - function Graphics (state, options) + function Graphics (scene, options) { var x = GetValue(options, 'x', 0); var y = GetValue(options, 'y', 0); - GameObject.call(this, state, 'Graphics'); + GameObject.call(this, scene, 'Graphics'); this.setPosition(x, y); @@ -44,12 +44,12 @@ var Graphics = new Class({ this.setDefaultStyles(options); - var resourceManager = state.game.renderer.resourceManager; + var resourceManager = scene.game.renderer.resourceManager; if (resourceManager !== undefined) { this.resourceManager = resourceManager; - this.gl = state.game.renderer.gl; + this.gl = scene.game.renderer.gl; } }, @@ -383,8 +383,8 @@ var Graphics = new Class({ generateTexture: function (key, width, height) { - var screenWidth = this.state.game.config.width; - var screenHeight = this.state.game.config.height; + var screenWidth = this.scene.game.config.width; + var screenHeight = this.scene.game.config.height; width = (typeof width === 'number') ? width : screenWidth; height = (typeof height === 'number') ? height : screenHeight; @@ -392,13 +392,13 @@ var Graphics = new Class({ Graphics.TargetCamera.scrollX = this.x; Graphics.TargetCamera.scrollY = this.y; - var texture = this.state.game.textures.createCanvas(key, width, height); + var texture = this.scene.game.textures.createCanvas(key, width, height); var ctx = texture.source[0].image.getContext('2d'); texture.add('__BASE', 0, 0, 0, width, height); - this.renderCanvas(this.state.game.renderer, this, 0, Graphics.TargetCamera, ctx); + this.renderCanvas(this.scene.game.renderer, this, 0, Graphics.TargetCamera, ctx); if (this.gl) { - this.state.game.renderer.uploadCanvasToGPU(ctx.canvas, texture.source[0].glTexture, true); + this.scene.game.renderer.uploadCanvasToGPU(ctx.canvas, texture.source[0].glTexture, true); } } diff --git a/v3/src/gameobjects/graphics/GraphicsCreator.js b/v3/src/gameobjects/graphics/GraphicsCreator.js index e9a432cc4..eab6fb75b 100644 --- a/v3/src/gameobjects/graphics/GraphicsCreator.js +++ b/v3/src/gameobjects/graphics/GraphicsCreator.js @@ -1,10 +1,8 @@ var Graphics = require('./Graphics'); -var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); -var BuildGameObject = require('../BuildGameObject'); -var GraphicsCreator = function (state, config) +var GraphicsCreator = function (scene, config) { - return new Graphics(state, config); + return new Graphics(scene, config); }; module.exports = GraphicsCreator; diff --git a/v3/src/gameobjects/graphics/GraphicsFactory.js b/v3/src/gameobjects/graphics/GraphicsFactory.js index 02d009a77..14bd425d0 100644 --- a/v3/src/gameobjects/graphics/GraphicsFactory.js +++ b/v3/src/gameobjects/graphics/GraphicsFactory.js @@ -1,8 +1,8 @@ var Graphics = require('./Graphics'); -var GraphicsFactory = function (state, config) +var GraphicsFactory = function (scene, config) { - return new Graphics(state, config); + return new Graphics(scene, config); }; module.exports = GraphicsFactory; diff --git a/v3/src/gameobjects/group/Group.js b/v3/src/gameobjects/group/Group.js index 9e98a8886..0e6ab3226 100644 --- a/v3/src/gameobjects/group/Group.js +++ b/v3/src/gameobjects/group/Group.js @@ -10,9 +10,9 @@ var Group = new Class({ initialize: - function Group (state, children, config) + function Group (scene, children, config) { - this.state = state; + this.scene = scene; this.children = new Set(children); @@ -64,13 +64,13 @@ var Group = new Class({ { if (visible === undefined) { visible = true; } - var child = new this.classType(this.state, x, y, key, frame); + var child = new this.classType(this.scene, x, y, key, frame); - this.state.sys.displayList.add(child); + this.scene.sys.displayList.add(child); if (child.preUpdate) { - this.state.sys.updateList.add(child); + this.scene.sys.updateList.add(child); } child.visible = visible; @@ -229,7 +229,7 @@ var Group = new Class({ { this.children.clear(); - this.state = undefined; + this.scene = undefined; this.children = undefined; }, diff --git a/v3/src/gameobjects/group/GroupCreator.js b/v3/src/gameobjects/group/GroupCreator.js index 7497a1c27..710c0addf 100644 --- a/v3/src/gameobjects/group/GroupCreator.js +++ b/v3/src/gameobjects/group/GroupCreator.js @@ -1,8 +1,8 @@ var Group = require('./Group'); -var GroupCreator = function (state, config) +var GroupCreator = function (scene, config) { - return new Group(state, null, config); + return new Group(scene, null, config); }; module.exports = GroupCreator; diff --git a/v3/src/gameobjects/group/GroupFactory.js b/v3/src/gameobjects/group/GroupFactory.js index c2184fa6a..36e86f135 100644 --- a/v3/src/gameobjects/group/GroupFactory.js +++ b/v3/src/gameobjects/group/GroupFactory.js @@ -1,8 +1,8 @@ var Group = require('./Group'); -var GroupFactory = function (state, children, config) +var GroupFactory = function (scene, children, config) { - return new Group(state, children, config); + return new Group(scene, children, config); }; module.exports = GroupFactory; diff --git a/v3/src/gameobjects/image/Image.js b/v3/src/gameobjects/image/Image.js index d78e62503..67b965d97 100644 --- a/v3/src/gameobjects/image/Image.js +++ b/v3/src/gameobjects/image/Image.js @@ -27,9 +27,9 @@ var Image = new Class({ initialize: - function Image (state, x, y, texture, frame) + function Image (scene, x, y, texture, frame) { - GameObject.call(this, state, 'Image'); + GameObject.call(this, scene, 'Image'); this.setTexture(texture, frame); this.setPosition(x, y); diff --git a/v3/src/gameobjects/image/ImageCreator.js b/v3/src/gameobjects/image/ImageCreator.js index 1db7642c1..63e78b914 100644 --- a/v3/src/gameobjects/image/ImageCreator.js +++ b/v3/src/gameobjects/image/ImageCreator.js @@ -2,14 +2,14 @@ var Image = require('./Image'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var BuildGameObject = require('../BuildGameObject'); -var ImageCreator = function (state, config) +var ImageCreator = function (scene, config) { var key = GetAdvancedValue(config, 'key', null); var frame = GetAdvancedValue(config, 'frame', null); - var image = new Image(state, 0, 0, key, frame); + var image = new Image(scene, 0, 0, key, frame); - BuildGameObject(state, image, config); + BuildGameObject(scene, image, config); return image; }; diff --git a/v3/src/gameobjects/image/ImageFactory.js b/v3/src/gameobjects/image/ImageFactory.js index 872ea736f..df9f7bd0d 100644 --- a/v3/src/gameobjects/image/ImageFactory.js +++ b/v3/src/gameobjects/image/ImageFactory.js @@ -1,8 +1,8 @@ var Image = require('./Image'); -var ImageFactory = function (state, x, y, key, frame) +var ImageFactory = function (scene, x, y, key, frame) { - return new Image(state, x, y, key, frame); + return new Image(scene, x, y, key, frame); }; module.exports = ImageFactory; diff --git a/v3/src/gameobjects/mesh/Mesh.js b/v3/src/gameobjects/mesh/Mesh.js index f55c42864..0a8168b2a 100644 --- a/v3/src/gameobjects/mesh/Mesh.js +++ b/v3/src/gameobjects/mesh/Mesh.js @@ -26,9 +26,9 @@ var Mesh = new Class({ initialize: - function Mesh (state, x, y, vertices, uv, indices, colors, alphas, texture, frame) + function Mesh (scene, x, y, vertices, uv, indices, colors, alphas, texture, frame) { - GameObject.call(this, state, 'Mesh'); + GameObject.call(this, scene, 'Mesh'); this.setTexture(texture, frame); this.setPosition(x, y); diff --git a/v3/src/gameobjects/mesh/MeshCreator.js b/v3/src/gameobjects/mesh/MeshCreator.js index 3f7fd5f5d..f2beac694 100644 --- a/v3/src/gameobjects/mesh/MeshCreator.js +++ b/v3/src/gameobjects/mesh/MeshCreator.js @@ -3,7 +3,7 @@ var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetValue = require('../../utils/object/GetValue'); var BuildGameObject = require('../BuildGameObject'); -var MeshCreator = function (state, config) +var MeshCreator = function (scene, config) { var key = GetAdvancedValue(config, 'key', null); var frame = GetAdvancedValue(config, 'frame', null); @@ -13,9 +13,9 @@ var MeshCreator = function (state, config) var alphas = GetValue(config, 'alphas', []); var uv = GetValue(config, 'uv', []); - var mesh = new Mesh(state, 0, 0, vertices, uv, indices, colors, alphas, key, frame); + var mesh = new Mesh(scene, 0, 0, vertices, uv, indices, colors, alphas, key, frame); - BuildGameObject(state, mesh, config); + BuildGameObject(scene, mesh, config); return mesh; }; diff --git a/v3/src/gameobjects/mesh/MeshFactory.js b/v3/src/gameobjects/mesh/MeshFactory.js index 00a6b77ec..8be5a3354 100644 --- a/v3/src/gameobjects/mesh/MeshFactory.js +++ b/v3/src/gameobjects/mesh/MeshFactory.js @@ -1,8 +1,8 @@ var Mesh = require('./Mesh'); -var MeshFactory = function (state, x, y, vertices, uv, key, frame) +var MeshFactory = function (scene, x, y, vertices, uv, key, frame) { - return new Mesh(state, x, y, vertices, uv, key, frame); + return new Mesh(scene, x, y, vertices, uv, key, frame); }; module.exports = MeshFactory; diff --git a/v3/src/gameobjects/pool/ObjectPool.js b/v3/src/gameobjects/pool/ObjectPool.js index 817e7d023..dca14c3f1 100644 --- a/v3/src/gameobjects/pool/ObjectPool.js +++ b/v3/src/gameobjects/pool/ObjectPool.js @@ -15,10 +15,10 @@ var ObjectPool = new Class({ if (callbackScope === undefined) { callbackScope = this; } this.manager = manager; - this.state = manager.state; + this.scene = manager.scene; - this.displayList = this.state.sys.displayList; - this.updateList = this.state.sys.updateList; + this.displayList = this.scene.sys.displayList; + this.updateList = this.scene.sys.updateList; this.createCallback = createCallback; this.callbackScope = callbackScope; @@ -32,7 +32,7 @@ var ObjectPool = new Class({ makeGameObject: function () { - var gameObject = new this.classType(this.state); + var gameObject = new this.classType(this.scene); this.displayList.add(gameObject); @@ -215,7 +215,7 @@ var ObjectPool = new Class({ destroy: function () { this.manager = undefined; - this.state = undefined; + this.scene = undefined; this.displayList = undefined; this.updateList = undefined; diff --git a/v3/src/gameobjects/pool/SpritePool.js b/v3/src/gameobjects/pool/SpritePool.js index 6a07bbd1a..e62e1d0e7 100644 --- a/v3/src/gameobjects/pool/SpritePool.js +++ b/v3/src/gameobjects/pool/SpritePool.js @@ -23,7 +23,7 @@ var SpritePool = new Class({ makeSprite: function () { - var gameObject = new this.classType(this.state, 0, 0, this.defaultKey, this.defaultFrame); + var gameObject = new this.classType(this.scene, 0, 0, this.defaultKey, this.defaultFrame); this.displayList.add(gameObject); this.updateList.add(gameObject); diff --git a/v3/src/gameobjects/quad/Quad.js b/v3/src/gameobjects/quad/Quad.js index 1687f2f2f..ee56ef045 100644 --- a/v3/src/gameobjects/quad/Quad.js +++ b/v3/src/gameobjects/quad/Quad.js @@ -8,7 +8,7 @@ var Quad = new Class({ initialize: - function Quad (state, x, y, texture, frame) + function Quad (scene, x, y, texture, frame) { // 0----3 // |\ B| @@ -25,7 +25,7 @@ var Quad = new Class({ var colors = [ 0xffffff, 0xffffff, 0xffffff, 0xffffff ]; var alphas = [ 1, 1, 1, 1 ]; - Mesh.call(this, state, x, y, vertices, uv, indices, colors, alphas, texture, frame); + Mesh.call(this, scene, x, y, vertices, uv, indices, colors, alphas, texture, frame); this.resetPosition(); }, diff --git a/v3/src/gameobjects/quad/QuadCreator.js b/v3/src/gameobjects/quad/QuadCreator.js index 82da0e664..ba409ce6d 100644 --- a/v3/src/gameobjects/quad/QuadCreator.js +++ b/v3/src/gameobjects/quad/QuadCreator.js @@ -2,16 +2,16 @@ var Quad = require('./Quad'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var BuildGameObject = require('../BuildGameObject'); -var QuadCreator = function (state, config) +var QuadCreator = function (scene, config) { var x = GetAdvancedValue(config, 'x', 0); var y = GetAdvancedValue(config, 'y', 0); var key = GetAdvancedValue(config, 'key', null); var frame = GetAdvancedValue(config, 'frame', null); - var quad = new Quad(state, x, y, key, frame); + var quad = new Quad(scene, x, y, key, frame); - BuildGameObject(state, quad, config); + BuildGameObject(scene, quad, config); return quad; }; diff --git a/v3/src/gameobjects/quad/QuadFactory.js b/v3/src/gameobjects/quad/QuadFactory.js index 3a703fc1b..eb9ece370 100644 --- a/v3/src/gameobjects/quad/QuadFactory.js +++ b/v3/src/gameobjects/quad/QuadFactory.js @@ -1,8 +1,8 @@ var Quad = require('./Quad'); -var QuadFactory = function (state, x, y, key, frame) +var QuadFactory = function (scene, x, y, key, frame) { - return new Quad(state, x, y, key, frame); + return new Quad(scene, x, y, key, frame); }; module.exports = QuadFactory; diff --git a/v3/src/gameobjects/renderpass/RenderPass.js b/v3/src/gameobjects/renderpass/RenderPass.js index 35ce545e3..babb50b97 100644 --- a/v3/src/gameobjects/renderpass/RenderPass.js +++ b/v3/src/gameobjects/renderpass/RenderPass.js @@ -33,16 +33,16 @@ var RenderPass = new Class({ initialize: - function RenderPass (state, x, y, width, height, shaderName, fragmentShader) + function RenderPass (scene, x, y, width, height, shaderName, fragmentShader) { - GameObject.call(this, state, 'RenderPass'); + GameObject.call(this, scene, 'RenderPass'); - var resourceManager = state.game.renderer.resourceManager; + var resourceManager = scene.game.renderer.resourceManager; var pot = ((width & (width - 1)) == 0 && (height & (height - 1)) == 0); var gl; var wrap; - this.renderer = state.game.renderer; + this.renderer = scene.game.renderer; this.passRenderTarget = null; this.renderTexture = null; this.passShader = null; @@ -51,12 +51,12 @@ var RenderPass = new Class({ if (resourceManager !== undefined) { - gl = state.game.renderer.gl; + gl = scene.game.renderer.gl; wrap = pot ? gl.REPEAT : gl.CLAMP_TO_EDGE; this.passShader = resourceManager.createShader(shaderName, {vert: TexturedAndNormalizedTintedShader.vert, frag: fragmentShader}); this.renderTexture = resourceManager.createTexture(0, gl.LINEAR, gl.LINEAR, wrap, wrap, gl.RGBA, null, width, height); this.passRenderTarget = resourceManager.createRenderTarget(width, height, this.renderTexture, null); - state.game.renderer.currentTexture = null; // force rebinding of prev texture + scene.game.renderer.currentTexture = null; // force rebinding of prev texture } this.flipY = true; diff --git a/v3/src/gameobjects/renderpass/RenderPassCreator.js b/v3/src/gameobjects/renderpass/RenderPassCreator.js index aca2560bb..a043cab02 100644 --- a/v3/src/gameobjects/renderpass/RenderPassCreator.js +++ b/v3/src/gameobjects/renderpass/RenderPassCreator.js @@ -2,7 +2,7 @@ var RenderPass = require('./RenderPass'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var BuildGameObject = require('../BuildGameObject'); -var RenderPassCreator = function (state, config) +var RenderPassCreator = function (scene, config) { var x = GetAdvancedValue(config, 'x', 0); var y = GetAdvancedValue(config, 'y', 0); @@ -11,9 +11,9 @@ var RenderPassCreator = function (state, config) var shaderName = GetAdvancedValue(config, 'shaderName', ''); var fragmentShader = GetAdvancedValue(config, 'fragmentShader', ''); - var pass = new RenderPass(state, x, y, width, height, shaderName, fragmentShader); + var pass = new RenderPass(scene, x, y, width, height, shaderName, fragmentShader); - BuildGameObject(state, pass, config); + BuildGameObject(scene, pass, config); return pass; }; diff --git a/v3/src/gameobjects/renderpass/RenderPassFactory.js b/v3/src/gameobjects/renderpass/RenderPassFactory.js index 520bc4b39..dedf99003 100644 --- a/v3/src/gameobjects/renderpass/RenderPassFactory.js +++ b/v3/src/gameobjects/renderpass/RenderPassFactory.js @@ -1,8 +1,8 @@ var RenderPass = require('./RenderPass'); -var RenderPassFactory = function (state, x, y, width, height, shaderName, fragmentShader) +var RenderPassFactory = function (scene, x, y, width, height, shaderName, fragmentShader) { - return new RenderPass(state, x, y, width, height, shaderName, fragmentShader); + return new RenderPass(scene, x, y, width, height, shaderName, fragmentShader); }; module.exports = RenderPassFactory; diff --git a/v3/src/gameobjects/sprite/Sprite.js b/v3/src/gameobjects/sprite/Sprite.js index a4232775c..2eb261ff3 100644 --- a/v3/src/gameobjects/sprite/Sprite.js +++ b/v3/src/gameobjects/sprite/Sprite.js @@ -27,9 +27,9 @@ var Sprite = new Class({ initialize: - function Sprite (state, x, y, texture, frame) + function Sprite (scene, x, y, texture, frame) { - GameObject.call(this, state, 'Sprite'); + GameObject.call(this, scene, 'Sprite'); this.anims = new Components.Animation(this); diff --git a/v3/src/gameobjects/sprite/SpriteCreator.js b/v3/src/gameobjects/sprite/SpriteCreator.js index 2270a8fe9..23bd0ef0e 100644 --- a/v3/src/gameobjects/sprite/SpriteCreator.js +++ b/v3/src/gameobjects/sprite/SpriteCreator.js @@ -3,14 +3,14 @@ var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var BuildGameObject = require('../BuildGameObject'); var BuildGameObjectAnimation = require('../BuildGameObjectAnimation'); -var SpriteCreator = function (state, config) +var SpriteCreator = function (scene, config) { var key = GetAdvancedValue(config, 'key', null); var frame = GetAdvancedValue(config, 'frame', null); - var sprite = new Sprite(state, 0, 0, key, frame); + var sprite = new Sprite(scene, 0, 0, key, frame); - BuildGameObject(state, sprite, config); + BuildGameObject(scene, sprite, config); // Sprite specific config options: diff --git a/v3/src/gameobjects/sprite/SpriteFactory.js b/v3/src/gameobjects/sprite/SpriteFactory.js index d92f13a18..80b0fc71e 100644 --- a/v3/src/gameobjects/sprite/SpriteFactory.js +++ b/v3/src/gameobjects/sprite/SpriteFactory.js @@ -1,8 +1,8 @@ var Sprite = require('./Sprite'); -var SpriteFactory = function (state, x, y, key, frame) +var SpriteFactory = function (scene, x, y, key, frame) { - return new Sprite(state, x, y, key, frame); + return new Sprite(scene, x, y, key, frame); }; module.exports = SpriteFactory; diff --git a/v3/src/gameobjects/text/static/Text.js b/v3/src/gameobjects/text/static/Text.js index c1898d679..4e5e316bc 100644 --- a/v3/src/gameobjects/text/static/Text.js +++ b/v3/src/gameobjects/text/static/Text.js @@ -28,13 +28,13 @@ var Text = new Class({ initialize: - function Text (state, x, y, text, style) + function Text (scene, x, y, text, style) { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } if (text === undefined) { text = ''; } - GameObject.call(this, state, 'Text'); + GameObject.call(this, scene, 'Text'); this.setPosition(x, y); this.setOrigin(0, 0); diff --git a/v3/src/gameobjects/text/static/TextCreator.js b/v3/src/gameobjects/text/static/TextCreator.js index 03181c1c7..83cd5f40c 100644 --- a/v3/src/gameobjects/text/static/TextCreator.js +++ b/v3/src/gameobjects/text/static/TextCreator.js @@ -2,7 +2,7 @@ var Text = require('./Text'); var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue'); var BuildGameObject = require('../../BuildGameObject'); -var TextCreator = function (state, config) +var TextCreator = function (scene, config) { // style Object = { // font: [ 'font', '16px Courier' ], @@ -26,9 +26,9 @@ var TextCreator = function (state, config) var content = GetAdvancedValue(config, 'text', ''); var style = GetAdvancedValue(config, 'style', null); - var text = new Text(state, 0, 0, content, style); + var text = new Text(scene, 0, 0, content, style); - BuildGameObject(state, text, config); + BuildGameObject(scene, text, config); // Text specific config options: diff --git a/v3/src/gameobjects/text/static/TextFactory.js b/v3/src/gameobjects/text/static/TextFactory.js index d7b515698..4ace01c2e 100644 --- a/v3/src/gameobjects/text/static/TextFactory.js +++ b/v3/src/gameobjects/text/static/TextFactory.js @@ -1,8 +1,8 @@ var Text = require('./Text'); -var TextFactory = function (state, x, y, text, style) +var TextFactory = function (scene, x, y, text, style) { - return new Text(state, x, y, text, style); + return new Text(scene, x, y, text, style); }; module.exports = TextFactory; diff --git a/v3/src/gameobjects/tilemap/dynamic/Tilemap.js b/v3/src/gameobjects/tilemap/dynamic/Tilemap.js index 779f3bd75..170c9dd46 100644 --- a/v3/src/gameobjects/tilemap/dynamic/Tilemap.js +++ b/v3/src/gameobjects/tilemap/dynamic/Tilemap.js @@ -27,9 +27,9 @@ var Tilemap = new Class({ initialize: - function Tilemap (state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) + function Tilemap (scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) { - GameObject.call(this, state, 'Tilemap'); + GameObject.call(this, scene, 'Tilemap'); this.mapData = mapData !== null ? new Uint32Array(mapData) : new Uint32Array(mapWidth * mapHeight); this.tileWidth = tileWidth; diff --git a/v3/src/gameobjects/tilemap/dynamic/TilemapCreator.js b/v3/src/gameobjects/tilemap/dynamic/TilemapCreator.js index ef880b379..2b3497315 100644 --- a/v3/src/gameobjects/tilemap/dynamic/TilemapCreator.js +++ b/v3/src/gameobjects/tilemap/dynamic/TilemapCreator.js @@ -2,7 +2,7 @@ var Tilemap = require('./Tilemap'); var GetValue = require('../../../utils/object/GetValue'); var BuildGameObject = require('../../BuildGameObject'); -var TilemapCreator = function (state, config) +var TilemapCreator = function (scene, config) { var mapData = GetValue(config, 'map.data', null); var mapWidth = GetValue(config, 'map.width', 1); @@ -17,9 +17,9 @@ var TilemapCreator = function (state, config) var tileFrame = GetValue(config, 'tile.frame', null); var tileBorder = GetValue(config, 'tile.border', 0); - var map = new Tilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, tileTexture, tileFrame); + var map = new Tilemap(scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, tileTexture, tileFrame); - BuildGameObject(state, map, config); + BuildGameObject(scene, map, config); return map; }; diff --git a/v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js b/v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js index 3881043ee..b6eff88cf 100644 --- a/v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js +++ b/v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js @@ -1,9 +1,9 @@ var Tilemap = require('./Tilemap'); -var TilemapFactory = function (state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) +var TilemapFactory = function (scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) { - return new Tilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame); + return new Tilemap(scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame); }; module.exports = TilemapFactory; diff --git a/v3/src/gameobjects/tilemap/static/StaticTilemap.js b/v3/src/gameobjects/tilemap/static/StaticTilemap.js index a33001b23..738b30fa5 100644 --- a/v3/src/gameobjects/tilemap/static/StaticTilemap.js +++ b/v3/src/gameobjects/tilemap/static/StaticTilemap.js @@ -27,14 +27,14 @@ var StaticTilemap = new Class({ initialize: - function StaticTilemap (state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) + function StaticTilemap (scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) { - GameObject.call(this, state, 'StaticTilemap'); + GameObject.call(this, scene, 'StaticTilemap'); this.vbo = null; - this.gl = state.game.renderer.gl ? state.game.renderer.gl : null; - this.tilemapRenderer = state.game.renderer.tilemapRenderer ? state.game.renderer.tilemapRenderer : null; - this.resourceManager = this.gl ? state.game.renderer.resourceManager : null; + this.gl = scene.game.renderer.gl ? scene.game.renderer.gl : null; + this.tilemapRenderer = scene.game.renderer.tilemapRenderer ? scene.game.renderer.tilemapRenderer : null; + this.resourceManager = this.gl ? scene.game.renderer.resourceManager : null; this.bufferData = null; this.mapData = mapData; this.tileWidth = tileWidth; diff --git a/v3/src/gameobjects/tilemap/static/StaticTilemapCreator.js b/v3/src/gameobjects/tilemap/static/StaticTilemapCreator.js index e289bc597..49b8dc8e2 100644 --- a/v3/src/gameobjects/tilemap/static/StaticTilemapCreator.js +++ b/v3/src/gameobjects/tilemap/static/StaticTilemapCreator.js @@ -2,7 +2,7 @@ var StaticTilemap = require('./StaticTilemap'); var GetValue = require('../../../utils/object/GetValue'); var BuildGameObject = require('../../BuildGameObject'); -var StaticTilemapCreator = function (state, config) +var StaticTilemapCreator = function (scene, config) { var mapData = GetValue(config, 'map.data', null); var mapWidth = GetValue(config, 'map.width', 1); @@ -17,9 +17,9 @@ var StaticTilemapCreator = function (state, config) var tileFrame = GetValue(config, 'tile.frame', null); var tileBorder = GetValue(config, 'tile.border', 0); - var map = new StaticTilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, tileTexture, tileFrame); + var map = new StaticTilemap(scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, tileTexture, tileFrame); - BuildGameObject(state, map, config); + BuildGameObject(scene, map, config); return map; }; diff --git a/v3/src/gameobjects/tilemap/static/StaticTilemapFactory.js b/v3/src/gameobjects/tilemap/static/StaticTilemapFactory.js index 4e25b9a12..fcae7a6e4 100644 --- a/v3/src/gameobjects/tilemap/static/StaticTilemapFactory.js +++ b/v3/src/gameobjects/tilemap/static/StaticTilemapFactory.js @@ -1,8 +1,8 @@ var StaticTilemap = require('./StaticTilemap'); -var StaticTilemapFactory = function (state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) +var StaticTilemapFactory = function (scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) { - return new StaticTilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame); + return new StaticTilemap(scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame); }; module.exports = StaticTilemapFactory; diff --git a/v3/src/gameobjects/tilesprite/TileSprite.js b/v3/src/gameobjects/tilesprite/TileSprite.js index e9ba73359..09ee68357 100644 --- a/v3/src/gameobjects/tilesprite/TileSprite.js +++ b/v3/src/gameobjects/tilesprite/TileSprite.js @@ -28,11 +28,11 @@ var TileSprite = new Class({ initialize: - function TileSprite (state, x, y, width, height, texture, frame) + function TileSprite (scene, x, y, width, height, texture, frame) { - var resourceManager = state.game.renderer.resourceManager; + var resourceManager = scene.game.renderer.resourceManager; - GameObject.call(this, state, 'TileSprite'); + GameObject.call(this, scene, 'TileSprite'); this.tilePositionX = 0; this.tilePositionY = 0; @@ -68,8 +68,8 @@ var TileSprite = new Class({ this.potHeight |= this.potHeight >> 16; this.potHeight++; - this.renderer = state.game.renderer; - var gl = state.game.renderer.gl; + this.renderer = scene.game.renderer; + var gl = scene.game.renderer.gl; this.tileTexture = resourceManager.createTexture(0, gl.LINEAR, gl.LINEAR, gl.REPEAT, gl.REPEAT, gl.RGBA, this.canvasBuffer, this.potWidth, this.potHeight); } diff --git a/v3/src/gameobjects/tilesprite/TileSpriteCreator.js b/v3/src/gameobjects/tilesprite/TileSpriteCreator.js index 8ee00c87a..977e8ac2b 100644 --- a/v3/src/gameobjects/tilesprite/TileSpriteCreator.js +++ b/v3/src/gameobjects/tilesprite/TileSpriteCreator.js @@ -2,7 +2,7 @@ var TileSprite = require('./TileSprite'); var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var BuildGameObject = require('../BuildGameObject'); -var TileSpriteCreator = function (state, config) +var TileSpriteCreator = function (scene, config) { var x = GetAdvancedValue(config, 'x', 0); var y = GetAdvancedValue(config, 'y', 0); @@ -11,9 +11,9 @@ var TileSpriteCreator = function (state, config) var key = GetAdvancedValue(config, 'key', ''); var frame = GetAdvancedValue(config, 'frame', ''); - var tile = new TileSprite(state, x, y, width, height, key, frame); + var tile = new TileSprite(scene, x, y, width, height, key, frame); - BuildGameObject(state, tile, config); + BuildGameObject(scene, tile, config); return tile; }; diff --git a/v3/src/gameobjects/tilesprite/TileSpriteFactory.js b/v3/src/gameobjects/tilesprite/TileSpriteFactory.js index bec3e553e..b7999ea5d 100644 --- a/v3/src/gameobjects/tilesprite/TileSpriteFactory.js +++ b/v3/src/gameobjects/tilesprite/TileSpriteFactory.js @@ -1,8 +1,8 @@ var TileSprite = require('./TileSprite'); -var TileSpriteFactory = function (state, x, y, width, height, key, frame) +var TileSpriteFactory = function (scene, x, y, width, height, key, frame) { - return new TileSprite(state, x, y, width, height, key, frame); + return new TileSprite(scene, x, y, width, height, key, frame); }; module.exports = TileSpriteFactory; diff --git a/v3/src/gameobjects/zone/Zone.js b/v3/src/gameobjects/zone/Zone.js index 7e75e25c3..2e791b488 100644 --- a/v3/src/gameobjects/zone/Zone.js +++ b/v3/src/gameobjects/zone/Zone.js @@ -19,9 +19,9 @@ var Zone = new Class({ initialize: - function Zone (state, x, y, width, height) + function Zone (scene, x, y, width, height) { - GameObject.call(this, state, 'Zone'); + GameObject.call(this, scene, 'Zone'); this.setPosition(x, y); this.setSize(width, height); diff --git a/v3/src/gameobjects/zone/ZoneFactory.js b/v3/src/gameobjects/zone/ZoneFactory.js index 85dfeca2b..ebd8cf84f 100644 --- a/v3/src/gameobjects/zone/ZoneFactory.js +++ b/v3/src/gameobjects/zone/ZoneFactory.js @@ -7,12 +7,12 @@ var ZoneFactory = { add: function (x, y, width, height) { - return new Zone(this.state, x, y, width, height); + return new Zone(this.scene, x, y, width, height); }, make: function (x, y, width, height) { - return new Zone(this.state, x, y, width, height); + return new Zone(this.scene, x, y, width, height); } }; diff --git a/v3/src/loader/BaseLoader.js b/v3/src/loader/BaseLoader.js index 20538f183..0c4acab98 100644 --- a/v3/src/loader/BaseLoader.js +++ b/v3/src/loader/BaseLoader.js @@ -24,7 +24,7 @@ var BaseLoader = new Class({ this.baseURL = ''; this.path = ''; - // Read from Game / State Config + // Read from Game / Scene Config this.enableParallel = true; this.maxParallelDownloads = 4; @@ -39,7 +39,7 @@ var BaseLoader = new Class({ this.queue = new Set(); this.storage = new Set(); - this._state = CONST.LOADER_IDLE; + this.state = CONST.LOADER_IDLE; }, addFile: function (file) @@ -59,18 +59,18 @@ var BaseLoader = new Class({ // Is the Loader actively loading (or processing loaded files) isLoading: function () { - return (this._state === CONST.LOADER_LOADING || this._state === CONST.LOADER_PROCESSING); + return (this.state === CONST.LOADER_LOADING || this.state === CONST.LOADER_PROCESSING); }, // Is the Loader ready to start a new load? isReady: function () { - return (this._state === CONST.LOADER_IDLE || this._state === CONST.LOADER_COMPLETE || this._state === CONST.LOADER_FAILED); + return (this.state === CONST.LOADER_IDLE || this.state === CONST.LOADER_COMPLETE || this.state === CONST.LOADER_FAILED); }, start: function () { - console.log(this.state.sys.settings.key, '- BaseLoader start. Files to load:', this.list.size); + console.log(this.scene.sys.settings.key, '- BaseLoader start. Files to load:', this.list.size); if (!this.isReady()) { @@ -85,7 +85,7 @@ var BaseLoader = new Class({ } else { - this._state = CONST.LOADER_LOADING; + this.state = CONST.LOADER_LOADING; this.failed.clear(); this.inflight.clear(); @@ -180,7 +180,7 @@ var BaseLoader = new Class({ { // console.log('---> BaseLoader.finishedLoading PROCESSING', this.queue.size, 'files'); - this._state = CONST.LOADER_PROCESSING; + this.state = CONST.LOADER_PROCESSING; this.storage.clear(); @@ -241,7 +241,7 @@ var BaseLoader = new Class({ { this.queue.delete(file); - if (this.queue.size === 0 && this._state === CONST.LOADER_PROCESSING) + if (this.queue.size === 0 && this.state === CONST.LOADER_PROCESSING) { // We've processed all the files we loaded this.processComplete(); @@ -250,7 +250,7 @@ var BaseLoader = new Class({ processComplete: function () { - console.log(this.state.sys.settings.key, '- Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size); + console.log(this.scene.sys.settings.key, '- Loader Complete. Loaded:', this.storage.size, 'Failed:', this.failed.size); this.list.clear(); this.inflight.clear(); @@ -261,7 +261,7 @@ var BaseLoader = new Class({ this.processCallback(); } - this._state = CONST.LOADER_COMPLETE; + this.state = CONST.LOADER_COMPLETE; this.events.dispatch(new Event.LOADER_COMPLETE_EVENT(this)); }, @@ -281,13 +281,13 @@ var BaseLoader = new Class({ this.path = ''; this.baseURL = ''; - this._state = CONST.LOADER_IDLE; + this.state = CONST.LOADER_IDLE; }, destroy: function () { this.reset(); - this._state = CONST.LOADER_DESTROYED; + this.state = CONST.LOADER_DESTROYED; } }); diff --git a/v3/src/phaser.js b/v3/src/phaser.js index 1ef5a7580..d752f0c44 100644 --- a/v3/src/phaser.js +++ b/v3/src/phaser.js @@ -28,7 +28,7 @@ var Phaser = { GameObjects: require('./gameobjects'), - State: require('./state/State'), + Scene: require('./scene/Scene'), Loader: { diff --git a/v3/src/plugins/CameraManager.js b/v3/src/plugins/CameraManager.js index 9fad4f7be..7da49d4ff 100644 --- a/v3/src/plugins/CameraManager.js +++ b/v3/src/plugins/CameraManager.js @@ -8,18 +8,18 @@ var CameraManager = new Class({ initialize: - function CameraManager (state) + function CameraManager (scene) { - // The State that owns this plugin - this.state = state; + // The Scene that owns this plugin + this.scene = scene; this.cameras = []; this.cameraPool = []; - if (state.sys.settings.cameras) + if (scene.sys.settings.cameras) { // We have cameras to create - this.fromJSON(state.sys.settings.cameras); + this.fromJSON(scene.sys.settings.cameras); } else { @@ -64,8 +64,8 @@ var CameraManager = new Class({ config = [ config ]; } - var gameWidth = this.state.sys.game.config.width; - var gameHeight = this.state.sys.game.config.height; + var gameWidth = this.scene.sys.game.config.width; + var gameHeight = this.scene.sys.game.config.height; for (var i = 0; i < config.length; i++) { @@ -117,8 +117,8 @@ var CameraManager = new Class({ { if (x === undefined) { x = 0; } if (y === undefined) { y = 0; } - if (width === undefined) { width = this.state.sys.game.config.width; } - if (height === undefined) { height = this.state.sys.game.config.height; } + if (width === undefined) { width = this.scene.sys.game.config.width; } + if (height === undefined) { height = this.scene.sys.game.config.height; } var camera = null; @@ -132,7 +132,7 @@ var CameraManager = new Class({ camera = new Camera(x, y, width, height); } - camera.setState(this.state); + camera.setScene(this.scene); this.cameras.push(camera); @@ -203,7 +203,7 @@ var CameraManager = new Class({ camera.preRender(); - renderer.render(this.state, children, interpolation, camera); + renderer.render(this.scene, children, interpolation, camera); } }, @@ -223,7 +223,7 @@ var CameraManager = new Class({ this.cameras = []; this.cameraPool = []; - this.state = undefined; + this.scene = undefined; } }); diff --git a/v3/src/plugins/DisplayList.js b/v3/src/plugins/DisplayList.js index b01294040..a778d77a1 100644 --- a/v3/src/plugins/DisplayList.js +++ b/v3/src/plugins/DisplayList.js @@ -4,10 +4,10 @@ var DisplayList = new Class({ initialize: - function DisplayList (state) + function DisplayList (scene) { - // The State that owns this plugin - this.state = state; + // The Scene that owns this plugin + this.scene = scene; // The objects that belong to this collection. // The equivalent of the old `Sprite.children` array. @@ -18,7 +18,7 @@ var DisplayList = new Class({ add: function (child) { - if (child.parent === this.state) + if (child.parent === this.scene) { return child; } @@ -27,7 +27,7 @@ var DisplayList = new Class({ child.parent.children.remove(child); } - child.parent = this.state; + child.parent = this.scene; this.list.push(child); @@ -50,7 +50,7 @@ var DisplayList = new Class({ child.parent.children.remove(child); } - child.parent = this.state; + child.parent = this.scene; this.list.splice(index, 0, child); } @@ -328,7 +328,7 @@ var DisplayList = new Class({ { return false; } - else if (child.parent === this.state) + else if (child.parent === this.scene) { return true; } @@ -347,7 +347,7 @@ var DisplayList = new Class({ */ bringToTop: function (child) { - if (child.parent === this.state && this.getIndex(child) < this.list.length) + if (child.parent === this.scene && this.getIndex(child) < this.list.length) { this.remove(child); this.add(child); @@ -365,7 +365,7 @@ var DisplayList = new Class({ */ sendToBack: function (child) { - if (child.parent === this.state && this.getIndex(child) > 0) + if (child.parent === this.scene && this.getIndex(child) > 0) { this.remove(child); this.addAt(child, 0); @@ -573,7 +573,7 @@ var DisplayList = new Class({ */ reparent: function (newParent) { - if (newParent !== this.state) + if (newParent !== this.scene) { for (var i = 0; i < this.list.length; i++) { diff --git a/v3/src/plugins/GameObjectCreator.js b/v3/src/plugins/GameObjectCreator.js index 2ce7e0639..e7628f333 100644 --- a/v3/src/plugins/GameObjectCreator.js +++ b/v3/src/plugins/GameObjectCreator.js @@ -20,84 +20,84 @@ var GameObjectCreator = new Class({ initialize: - function GameObjectCreator (state) + function GameObjectCreator (scene) { - this.state = state; + this.scene = scene; }, bitmapText: function (config) { - return StaticBitmapTextCreator(this.state, config); + return StaticBitmapTextCreator(this.scene, config); }, dynamicBitmapText: function (config) { - return DynamicBitmapTextCreator(this.state, config); + return DynamicBitmapTextCreator(this.scene, config); }, blitter: function (config) { - return BlitterCreator(this.state, config); + return BlitterCreator(this.scene, config); }, effectLayer: function (config) { - return EffectLayerCreator(this.state, config); + return EffectLayerCreator(this.scene, config); }, graphics: function (config) { - return GraphicsCreator(this.state, config); + return GraphicsCreator(this.scene, config); }, group: function (config) { - return GroupCreator(this.state, config); + return GroupCreator(this.scene, config); }, mesh: function (config) { - return MeshCreator(this.state, config); + return MeshCreator(this.scene, config); }, image: function (config) { - return ImageCreator(this.state, config); + return ImageCreator(this.scene, config); }, quad: function (config) { - return QuadCreator(this.state, config); + return QuadCreator(this.scene, config); }, renderPass: function (config) { - return RenderPassCreator(this.state, config); + return RenderPassCreator(this.scene, config); }, sprite: function (config) { - return SpriteCreator(this.state, config); + return SpriteCreator(this.scene, config); }, text: function (config) { - return TextCreator(this.state, config); + return TextCreator(this.scene, config); }, tilemap: function (config) { - return DynamicTilemapCreator(this.state, config); + return DynamicTilemapCreator(this.scene, config); }, staticTilemap: function (config) { - return StaticTilemapCreator(this.state, config); + return StaticTilemapCreator(this.scene, config); }, tileSprite: function (config) { - return TileSpriteCreator(this.state, config); + return TileSpriteCreator(this.scene, config); } }); diff --git a/v3/src/plugins/GameObjectFactory.js b/v3/src/plugins/GameObjectFactory.js index c68806883..1c65465dc 100644 --- a/v3/src/plugins/GameObjectFactory.js +++ b/v3/src/plugins/GameObjectFactory.js @@ -20,12 +20,12 @@ var GameObjectFactory = new Class({ initialize: - function GameObjectFactory (state) + function GameObjectFactory (scene) { - this.state = state; + this.scene = scene; - this.displayList = state.sys.displayList; - this.updateList = state.sys.updateList; + this.displayList = scene.sys.displayList; + this.updateList = scene.sys.updateList; }, existing: function (child) @@ -45,57 +45,57 @@ var GameObjectFactory = new Class({ bitmapText: function (x, y, font, text, size, align) { - return this.displayList.add(StaticBitmapTextFactory(this.state, x, y, font, text, size, align)); + return this.displayList.add(StaticBitmapTextFactory(this.scene, x, y, font, text, size, align)); }, dynamicBitmapText: function (x, y, font, text, size, align) { - return this.displayList.add(DynamicBitmapTextFactory(this.state, x, y, font, text, size, align)); + return this.displayList.add(DynamicBitmapTextFactory(this.scene, x, y, font, text, size, align)); }, blitter: function (x, y, key, frame) { - return this.displayList.add(BlitterFactory(this.state, x, y, key, frame)); + return this.displayList.add(BlitterFactory(this.scene, x, y, key, frame)); }, effectLayer: function (x, y, width, height, effectName, fragmentShader) { - return this.displayList.add(EffectLayerFactory(this.state, x, y, width, height, effectName, fragmentShader)); + return this.displayList.add(EffectLayerFactory(this.scene, x, y, width, height, effectName, fragmentShader)); }, graphics: function (config) { - return this.displayList.add(GraphicsFactory(this.state, config)); + return this.displayList.add(GraphicsFactory(this.scene, config)); }, group: function (displayList, config) { - return GroupFactory(this.state, displayList, config); + return GroupFactory(this.scene, displayList, config); }, image: function (x, y, key, frame) { - return this.displayList.add(ImageFactory(this.state, x, y, key, frame)); + return this.displayList.add(ImageFactory(this.scene, x, y, key, frame)); }, mesh: function (x, y, vertices, uv, key, frame) { - return this.displayList.add(MeshFactory(this.state, x, y, vertices, uv, key, frame)); + return this.displayList.add(MeshFactory(this.scene, x, y, vertices, uv, key, frame)); }, quad: function (x, y, key, frame) { - return this.displayList.add(QuadFactory(this.state, x, y, key, frame)); + return this.displayList.add(QuadFactory(this.scene, x, y, key, frame)); }, renderPass: function (x, y, width, height, shaderName, fragmentShader) { - return this.displayList.add(RenderPassFactory(this.state, x, y, width, height, shaderName, fragmentShader)); + return this.displayList.add(RenderPassFactory(this.scene, x, y, width, height, shaderName, fragmentShader)); }, sprite: function (x, y, key, frame) { - var sprite = SpriteFactory(this.state, x, y, key, frame); + var sprite = SpriteFactory(this.scene, x, y, key, frame); this.displayList.add(sprite); this.updateList.add(sprite); @@ -105,22 +105,22 @@ var GameObjectFactory = new Class({ text: function (x, y, text, style) { - return this.displayList.add(TextFactory(this.state, x, y, text, style)); + return this.displayList.add(TextFactory(this.scene, x, y, text, style)); }, tilemap: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) { - return this.displayList.add(DynamicTilemapFactory(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)); + return this.displayList.add(DynamicTilemapFactory(this.scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)); }, staticTilemap: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame) { - return this.displayList.add(StaticTilemapFactory(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)); + return this.displayList.add(StaticTilemapFactory(this.scene, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileBorder, texture, frame)); }, tileSprite: function (x, y, width, height, key, frame) { - return this.displayList.add(TileSpriteFactory(this.state, x, y, width, height, key, frame)); + return this.displayList.add(TileSpriteFactory(this.scene, x, y, width, height, key, frame)); } }); diff --git a/v3/src/plugins/InputManager.js b/v3/src/plugins/InputManager.js index 5c0b5ea23..da6f23f8a 100644 --- a/v3/src/plugins/InputManager.js +++ b/v3/src/plugins/InputManager.js @@ -5,17 +5,17 @@ var InputManager = new Class({ initialize: - function InputManager (state, game) + function InputManager (scene, game) { - // The State that owns this plugin - this.state = state; + // The Scene that owns this plugin + this.scene = scene; this.cameras; // GlobalInputManager this.manager = game.input; - // Should use State event dispatcher? + // Should use Scene event dispatcher? this.events = this.manager.events; this.keyboard = this.manager.keyboard; @@ -36,7 +36,7 @@ var InputManager = new Class({ boot: function () { - this.cameras = this.state.sys.cameras.cameras; + this.cameras = this.scene.sys.cameras.cameras; }, begin: function () @@ -90,7 +90,7 @@ var InputManager = new Class({ return; } - // Has the pointer moved? If so we need to re-check the interactive objects per camera in this State + // Has the pointer moved? If so we need to re-check the interactive objects per camera in this Scene if (this.manager.activePointer.dirty) { this.hitTestPointer(this.manager.activePointer); diff --git a/v3/src/plugins/Loader.js b/v3/src/plugins/Loader.js index 39cc2c837..9e4216e2a 100644 --- a/v3/src/plugins/Loader.js +++ b/v3/src/plugins/Loader.js @@ -1,6 +1,6 @@ var BaseLoader = require('../loader/BaseLoader'); var Class = require('../utils/Class'); -var CONST = require('../loader/const'); +// var CONST = require('../loader/const'); var NumberArray = require('../utils/array/NumberArray'); var AnimationJSONFile = require('../loader/filetypes/AnimationJSONFile'); @@ -25,15 +25,15 @@ var Loader = new Class({ initialize: - function Loader (state) + function Loader (scene) { BaseLoader.call(this); /** - * @property {Phaser.State} state - The State that owns this Factory + * @property {Phaser.Scene} scene - The Scene that owns this Factory * @protected */ - this.state = state; + this.scene = scene; this._multilist = {}; }, @@ -248,9 +248,9 @@ var Loader = new Class({ } // The global Texture Manager - var cache = this.state.sys.cache; - var textures = this.state.sys.textures; - var anims = this.state.sys.anims; + var cache = this.scene.sys.cache; + var textures = this.scene.sys.textures; + var anims = this.scene.sys.anims; // Process multiatlas groups first diff --git a/v3/src/plugins/PoolManager.js b/v3/src/plugins/PoolManager.js index 46a6435d2..133e72d4e 100644 --- a/v3/src/plugins/PoolManager.js +++ b/v3/src/plugins/PoolManager.js @@ -6,9 +6,9 @@ var PoolManager = new Class({ initialize: - function PoolManager (state) + function PoolManager (scene) { - this.state = state; + this.scene = scene; this._active = []; this._pendingInsertion = []; @@ -102,7 +102,7 @@ var PoolManager = new Class({ this.processing = false; }, - // State that owns this Pool is shutting down + // Scene that owns this Pool is shutting down shutdown: function () { var i; @@ -132,7 +132,7 @@ var PoolManager = new Class({ { this.shutdown(); - this.state = undefined; + this.scene = undefined; } }); diff --git a/v3/src/plugins/StateManager.js b/v3/src/plugins/SceneManager.js similarity index 79% rename from v3/src/plugins/StateManager.js rename to v3/src/plugins/SceneManager.js index 318826051..99776906f 100644 --- a/v3/src/plugins/StateManager.js +++ b/v3/src/plugins/SceneManager.js @@ -1,21 +1,21 @@ var Class = require('../utils/Class'); -// A proxy class to the Global State Manager -var StateManager = new Class({ +// A proxy class to the Global Scene Manager +var SceneManager = new Class({ initialize: - function StateManager (state, game) + function SceneManager (scene, game) { - // The State that owns this plugin - this.state = state; + // The Scene that owns this plugin + this.scene = scene; - this.settings = state.sys.settings; + this.settings = scene.sys.settings; - this.key = state.sys.settings.key; + this.key = scene.sys.settings.key; - // GlobalStateManager - this.manager = game.state; + // GlobalSceneManager + this.manager = game.scene; // Private this._queue = []; @@ -101,7 +101,7 @@ var StateManager = new Class({ this._queue.length = 0; }, - // Shutdown this State and run the given one + // Shutdown this Scene and run the given one start: function (key, data) { if (key === undefined) { key = this.key; } @@ -111,15 +111,15 @@ var StateManager = new Class({ return this; }, - // Add the State into the State Manager and start it if 'autoStart' is true or the State config 'active' property is set - add: function (key, stateConfig, autoStart) + // Add the Scene into the Scene Manager and start it if 'autoStart' is true or the Scene config 'active' property is set + add: function (key, sceneConfig, autoStart) { - this._queue.push({ type: 'add', key: key, data: stateConfig, autoStart: autoStart }); + this._queue.push({ type: 'add', key: key, data: sceneConfig, autoStart: autoStart }); return this; }, - // Launch the given State and run it in parallel with this one + // Launch the given Scene and run it in parallel with this one launch: function (key, data) { if (key === undefined) { key = this.key; } @@ -129,7 +129,7 @@ var StateManager = new Class({ return this; }, - // Pause the State - this stops the update step from happening but it still renders + // Pause the Scene - this stops the update step from happening but it still renders pause: function (key) { if (key === undefined) { key = this.key; } @@ -139,7 +139,7 @@ var StateManager = new Class({ return this; }, - // Resume the State - starts the update loop again + // Resume the Scene - starts the update loop again resume: function (key) { if (key === undefined) { key = this.key; } @@ -149,7 +149,7 @@ var StateManager = new Class({ return this; }, - // Makes the State sleep (no update, no render) but doesn't shutdown + // Makes the Scene sleep (no update, no render) but doesn't shutdown sleep: function (key) { this._queue.push({ type: 'sleep', key: key }); @@ -157,7 +157,7 @@ var StateManager = new Class({ return this; }, - // Makes the State wake-up (starts update and render) + // Makes the Scene wake-up (starts update and render) wake: function (key) { this._queue.push({ type: 'wake', key: key }); @@ -165,7 +165,7 @@ var StateManager = new Class({ return this; }, - // Makes this State sleep then starts the State given + // Makes this Scene sleep then starts the Scene given swap: function (key) { this._queue.push({ type: 'swap', key: key }); @@ -173,7 +173,7 @@ var StateManager = new Class({ return this; }, - // Shutdown the State, clearing display list, timers, etc + // Shutdown the Scene, clearing display list, timers, etc stop: function (key) { if (key === undefined) { key = this.key; } @@ -217,7 +217,7 @@ var StateManager = new Class({ get: function (key) { - return this.manager.getState(key); + return this.manager.getScene(key); }, transitionTo: function (key, duration) @@ -233,4 +233,4 @@ var StateManager = new Class({ }); -module.exports = StateManager; +module.exports = SceneManager; diff --git a/v3/src/plugins/UpdateList.js b/v3/src/plugins/UpdateList.js index 0b4abb5c2..d1db97e27 100644 --- a/v3/src/plugins/UpdateList.js +++ b/v3/src/plugins/UpdateList.js @@ -4,9 +4,9 @@ var UpdateList = new Class({ initialize: - function UpdateList (state) + function UpdateList (scene) { - this.state = state; + this.scene = scene; this._list = []; this._pendingInsertion = []; @@ -69,7 +69,7 @@ var UpdateList = new Class({ } }, - // State that owns this Clock is shutting down + // Scene that owns this Clock is shutting down shutdown: function () { var i; @@ -99,7 +99,7 @@ var UpdateList = new Class({ { this.shutdown(); - this.state = undefined; + this.scene = undefined; } }); diff --git a/v3/src/renderer/canvas/CanvasRenderer.js b/v3/src/renderer/canvas/CanvasRenderer.js index b9d7a3764..1bc5c748b 100644 --- a/v3/src/renderer/canvas/CanvasRenderer.js +++ b/v3/src/renderer/canvas/CanvasRenderer.js @@ -24,7 +24,7 @@ var CanvasRenderer = new Class({ this.drawCount = 0; - // Read all the following from game config (or State config?) + // Read all the following from game config (or Scene config?) // this.clearBeforeRender = true; // this.transparent = false; // this.autoResize = false; @@ -148,20 +148,20 @@ var CanvasRenderer = new Class({ }, /** - * Renders the State. + * Renders the Scene. * * @method render - * @param {Phaser.State} state - The State to be rendered. + * @param {Phaser.Scene} scene - The Scene to be rendered. * @param {number} interpolationPercentage - The cumulative amount of time that hasn't been simulated yet, divided * by the amount of time that will be simulated the next time update() * runs. Useful for interpolating frames. */ - render: function (state, children, interpolationPercentage, camera) + render: function (scene, children, interpolationPercentage, camera) { - var w = state.sys.width; - var h = state.sys.height; - var ctx = state.sys.context; - var settings = state.sys.settings; + // var w = scene.sys.width; + // var h = scene.sys.height; + var ctx = scene.sys.context; + var settings = scene.sys.settings; var scissor = (camera.x !== 0 || camera.y !== 0 || camera.width !== ctx.canvas.width || camera.height !== ctx.canvas.height); var list = children.list; @@ -211,8 +211,8 @@ var CanvasRenderer = new Class({ child.renderCanvas(this, child, interpolationPercentage, camera); } - // Call the State.render function - state.render.call(state, ctx, interpolationPercentage); + // Call the Scene.render function + scene.render.call(scene, ctx, interpolationPercentage); ctx.setTransform(1, 0, 0, 1, 0, 0); @@ -238,10 +238,10 @@ var CanvasRenderer = new Class({ } // Blast it to the Game Canvas (if needed) - if (settings.renderToTexture) - { - this.gameContext.drawImage(state.sys.canvas, 0, 0, w, h, settings.x, settings.y, w, h); - } + // if (settings.renderToTexture) + // { + // this.gameContext.drawImage(scene.sys.canvas, 0, 0, w, h, settings.x, settings.y, w, h); + // } }, postRender: function () diff --git a/v3/src/renderer/webgl/WebGLRenderer.js b/v3/src/renderer/webgl/WebGLRenderer.js index eed3aa246..7f3de1d52 100644 --- a/v3/src/renderer/webgl/WebGLRenderer.js +++ b/v3/src/renderer/webgl/WebGLRenderer.js @@ -295,15 +295,15 @@ var WebGLRenderer = new Class({ }, /** - * Renders a single State. + * Renders a single Scene. * * @method render - * @param {Phaser.State} state - The State to be rendered. + * @param {Phaser.Scene} scene - The Scene to be rendered. * @param {number} interpolationPercentage - The cumulative amount of time that hasn't been simulated yet, divided * by the amount of time that will be simulated the next time update() * runs. Useful for interpolating frames. */ - render: function (state, children, interpolationPercentage, camera) + render: function (scene, children, interpolationPercentage, camera) { var gl = this.gl; var quadBatch = this.quadBatch; diff --git a/v3/src/state/FactoryMap.js b/v3/src/scene/FactoryMap.js similarity index 76% rename from v3/src/state/FactoryMap.js rename to v3/src/scene/FactoryMap.js index e84562235..51012e7c5 100644 --- a/v3/src/state/FactoryMap.js +++ b/v3/src/scene/FactoryMap.js @@ -1,4 +1,4 @@ -// These properties get injected into the State Factory Plugin +// These properties get injected into the Scene Factory Plugin // The key is the factory reference, the value is the Game Object that is created // These can be modified via the config object diff --git a/v3/src/state/GlobalStateManager.js b/v3/src/scene/GlobalSceneManager.js similarity index 58% rename from v3/src/state/GlobalStateManager.js rename to v3/src/scene/GlobalSceneManager.js index d1f0d5f75..f2c7dce75 100644 --- a/v3/src/state/GlobalStateManager.js +++ b/v3/src/scene/GlobalSceneManager.js @@ -1,39 +1,39 @@ var Components = require('./components/'); var Class = require('../utils/Class'); -var GlobalStateManager = new Class({ +var GlobalSceneManager = new Class({ initialize: - function GlobalStateManager (game, stateConfig) + function GlobalSceneManager (game, sceneConfig) { this.game = game; // Everything kept in here this.keys = {}; - this.states = []; + this.scenes = []; - // Only active states are kept in here. They are moved here when started, and moved out when not. - // All states are stored in the states array, regardless of being active or not. + // Only active scenes are kept in here. They are moved here when started, and moved out when not. + // All scenes are stored in the scenes array, regardless of being active or not. this.active = []; - // A state pending to be added to the State Manager is stored in here until the manager has time to add it. + // A scene pending to be added to the Scene Manager is stored in here until the manager has time to add it. this._pending = []; - // An array of states waiting to be started once the game has booted + // An array of scenes waiting to be started once the game has booted this._start = []; - if (stateConfig) + if (sceneConfig) { - if (Array.isArray(stateConfig)) + if (Array.isArray(sceneConfig)) { - for (var i = 0; i < stateConfig.length; i++) + for (var i = 0; i < sceneConfig.length; i++) { - // The i === 0 part just starts the first State given + // The i === 0 part just starts the first Scene given this._pending.push({ index: i, key: 'default', - state: stateConfig[i], + scene: sceneConfig[i], autoStart: (i === 0), data: {} }); @@ -44,7 +44,7 @@ var GlobalStateManager = new Class({ this._pending.push({ index: 0, key: 'default', - state: stateConfig, + scene: sceneConfig, autoStart: true, data: {} }); @@ -54,21 +54,21 @@ var GlobalStateManager = new Class({ add: Components.Add, boot: Components.Boot, - bootState: Components.BootState, + bootScene: Components.BootScene, bringToTop: Components.BringToTop, create: Components.Create, - createStateDisplay: Components.CreateStateDisplay, - createStateFromFunction: Components.CreateStateFromFunction, - createStateFromInstance: Components.CreateStateFromInstance, - createStateFromObject: Components.CreateStateFromObject, - getActiveState: Components.GetActiveState, - getActiveStateIndex: Components.GetActiveStateIndex, - getActiveStateIndexByKey: Components.GetActiveStateIndexByKey, + createSceneDisplay: Components.CreateSceneDisplay, + createSceneFromFunction: Components.CreateSceneFromFunction, + createSceneFromInstance: Components.CreateSceneFromInstance, + createSceneFromObject: Components.CreateSceneFromObject, + getActiveScene: Components.GetActiveScene, + getActiveSceneIndex: Components.GetActiveSceneIndex, + getActiveSceneIndexByKey: Components.GetActiveSceneIndexByKey, getKey: Components.GetKey, - getState: Components.GetState, - getStateAt: Components.GetStateAt, - getStateIndex: Components.GetStateIndex, - getStateIndexByKey: Components.GetStateIndexByKey, + getScene: Components.GetScene, + getSceneAt: Components.GetSceneAt, + getSceneIndex: Components.GetSceneIndex, + getSceneIndexByKey: Components.GetSceneIndexByKey, isActive: Components.IsActive, isSleeping: Components.IsSleeping, loadComplete: Components.LoadComplete, @@ -88,4 +88,4 @@ var GlobalStateManager = new Class({ }); -module.exports = GlobalStateManager; +module.exports = GlobalSceneManager; diff --git a/v3/src/state/InjectionMap.js b/v3/src/scene/InjectionMap.js similarity index 80% rename from v3/src/state/InjectionMap.js rename to v3/src/scene/InjectionMap.js index 26faabe68..f5d2074d5 100644 --- a/v3/src/state/InjectionMap.js +++ b/v3/src/scene/InjectionMap.js @@ -1,5 +1,5 @@ -// These properties get injected into the State and map to local systems -// The key is the local system reference, the value is the property that is added to the State +// These properties get injected into the Scene and map to local systems +// The key is the local system reference, the value is the property that is added to the Scene // These can be modified via the config object var InjectionMap = { @@ -20,7 +20,7 @@ var InjectionMap = { load: 'load', make: 'make', pool: 'pool', - stateManager: 'state', + sceneManager: 'scene', time: 'time', tweens: 'tweens' diff --git a/v3/src/state/State.js b/v3/src/scene/Scene.js similarity index 53% rename from v3/src/state/State.js rename to v3/src/scene/Scene.js index 67423de37..bb26e7c25 100644 --- a/v3/src/state/State.js +++ b/v3/src/scene/Scene.js @@ -2,26 +2,26 @@ var Class = require('../utils/Class'); var Systems = require('./Systems'); -var State = new Class({ +var Scene = new Class({ initialize: - function State (config) + function Scene (config) { - // The State Systems. You must never overwrite this property, or all hell will break lose. + // The Scene Systems. You must never overwrite this property, or all hell will break lose. this.sys = new Systems(this, config); }, - // Should be overridden by your own States + // Should be overridden by your own Scenes update: function () { }, - // Should be overridden by your own States + // Should be overridden by your own Scenes render: function () { } }); -module.exports = State; +module.exports = Scene; diff --git a/v3/src/state/Settings.js b/v3/src/scene/Settings.js similarity index 92% rename from v3/src/state/Settings.js rename to v3/src/scene/Settings.js index 16265c73f..7dd90033d 100644 --- a/v3/src/state/Settings.js +++ b/v3/src/scene/Settings.js @@ -37,11 +37,11 @@ var Settings = { cameras: GetValue(config, 'cameras', null), - // State Property Injection Map + // Scene Property Injection Map map: GetValue(config, 'map', InjectionMap), - // State Render Settings (applies only to this State) + // Scene Render Settings (applies only to this Scene) scaleMode: GetValue(config, 'scaleMode', ScaleModes.DEFAULT), roundPixels: GetValue(config, 'roundPixels', false), diff --git a/v3/src/state/Systems.js b/v3/src/scene/Systems.js similarity index 68% rename from v3/src/state/Systems.js rename to v3/src/scene/Systems.js index 301849f1d..139b53afb 100644 --- a/v3/src/state/Systems.js +++ b/v3/src/scene/Systems.js @@ -12,7 +12,7 @@ var Loader = require('../plugins/Loader'); var PoolManager = require('../plugins/PoolManager'); var Settings = require('./Settings'); var StableSort = require('../utils/array/StableSort'); -var StateManager = require('../plugins/StateManager'); +var SceneManager = require('../plugins/SceneManager'); var TweenManager = require('../tween/TweenManager'); var UpdateList = require('../plugins/UpdateList'); @@ -20,16 +20,16 @@ var Systems = new Class({ initialize: - function Systems (state, config) + function Systems (scene, config) { - this.state = state; + this.scene = scene; this.config = config; this.settings = Settings.create(config); this.sortChildrenFlag = false; - // Set by the GlobalStateManager + // Set by the GlobalSceneManager this.mask = null; this.canvas; this.context; @@ -43,7 +43,7 @@ var Systems = new Class({ this.registry; this.textures; - // Reference to State specific managers (Factory, Tweens, Loader, Physics, etc) + // Reference to Scene specific managers (Factory, Tweens, Loader, Physics, etc) this.add; this.cameras; this.events; @@ -51,11 +51,11 @@ var Systems = new Class({ this.load; this.make; this.pool; - this.stateManager; + this.sceneManager; this.time; this.tweens; - // State properties + // Scene properties this.updateList; this.displayList; this.data; @@ -63,7 +63,7 @@ var Systems = new Class({ init: function (game) { - var state = this.state; + var scene = this.scene; this.game = game; @@ -74,24 +74,24 @@ var Systems = new Class({ this.registry = game.registry; this.textures = game.textures; - // State specific properties (transform, data, children, etc) + // Scene specific properties (transform, data, children, etc) - this.inputManager = new InputManager(state, game); - this.updateList = new UpdateList(state); - this.displayList = new DisplayList(state); - this.data = new Data(state); + this.inputManager = new InputManager(scene, game); + this.updateList = new UpdateList(scene); + this.displayList = new DisplayList(scene); + this.data = new Data(scene); - // State specific managers (Factory, Tweens, Loader, Physics, etc) + // Scene specific managers (Factory, Tweens, Loader, Physics, etc) - this.add = new GameObjectFactory(state); - this.cameras = new CameraManager(state); + this.add = new GameObjectFactory(scene); + this.cameras = new CameraManager(scene); this.events = new EventDispatcher(); - this.load = new Loader(state); - this.make = new GameObjectCreator(state); - this.pool = new PoolManager(state); - this.stateManager = new StateManager(state, game); - this.time = new Clock(state); - this.tweens = new TweenManager(state); + this.load = new Loader(scene); + this.make = new GameObjectCreator(scene); + this.pool = new PoolManager(scene); + this.sceneManager = new SceneManager(scene, game); + this.time = new Clock(scene); + this.tweens = new TweenManager(scene); // Sometimes the managers need access to a system created after them this.inputManager.boot(); @@ -110,14 +110,14 @@ var Systems = new Class({ continue; } - this.state[map[key]] = this[key]; + this.scene[map[key]] = this[key]; } }, step: function (time, delta) { - // Are there any pending StateManager actions? - this.stateManager.update(); + // Are there any pending SceneManager actions? + this.sceneManager.update(); if (!this.settings.active) { @@ -137,7 +137,7 @@ var Systems = new Class({ this.cameras.update(time, delta); this.inputManager.update(time, delta); - this.state.update.call(this.state, time, delta); + this.scene.update.call(this.scene, time, delta); }, render: function (interpolation, renderer) @@ -168,60 +168,60 @@ var Systems = new Class({ return childA._z - childB._z; }, - // A paused State still renders, it just doesn't run ANY of its update handlers or systems + // A paused Scene still renders, it just doesn't run ANY of its update handlers or systems pause: function () { - // Was paused by the GlobalStateManager + // Was paused by the GlobalSceneManager this.settings.active = false; - if (this.state.pause) + if (this.scene.pause) { - this.state.pause.call(this.state); + this.scene.pause.call(this.scene); } }, resume: function () { - // Was resumed by the GlobalStateManager + // Was resumed by the GlobalSceneManager this.settings.active = true; - if (this.state.resume) + if (this.scene.resume) { - this.state.resume.call(this.state); + this.scene.resume.call(this.scene); } }, sleep: function () { - // Was sent to sleep by the GlobalStateManager + // Was sent to sleep by the GlobalSceneManager this.settings.active = false; this.settings.visible = false; - if (this.state.sleep) + if (this.scene.sleep) { - this.state.sleep.call(this.state); + this.scene.sleep.call(this.scene); } }, wake: function () { - // Was woken up by the GlobalStateManager + // Was woken up by the GlobalSceneManager this.settings.active = true; this.settings.visible = true; - if (this.state.wake) + if (this.scene.wake) { - this.state.wake.call(this.state); + this.scene.wake.call(this.scene); } }, start: function (data) { - // Was started by the GlobalStateManager + // Was started by the GlobalSceneManager this.settings.data = data; @@ -231,7 +231,7 @@ var Systems = new Class({ shutdown: function () { - // Was stopped by the GlobalStateManager + // Was stopped by the GlobalSceneManager this.settings.active = false; this.settings.visible = false; @@ -242,9 +242,9 @@ var Systems = new Class({ this.time.shutdown(); this.tweens.shutdown(); - if (this.state.shutdown) + if (this.scene.shutdown) { - this.state.shutdown.call(this.state); + this.scene.shutdown.call(this.scene); } }, @@ -258,9 +258,9 @@ var Systems = new Class({ this.tweens.destroy(); // etc - if (this.state.destroy) + if (this.scene.destroy) { - this.state.destroy.call(this.state); + this.scene.destroy.call(this.scene); } } diff --git a/v3/src/scene/components/Add.js b/v3/src/scene/components/Add.js new file mode 100644 index 000000000..b991808fc --- /dev/null +++ b/v3/src/scene/components/Add.js @@ -0,0 +1,89 @@ +var Scene = require('../Scene'); + +/** +* Adds a new Scene into the GlobalSceneManager. You must give each Scene a unique key by which you'll identify it. +* The Scene can be either a Phaser.Scene object (or an object that extends it), a plain JavaScript object or a function. +* If a function is given a new scene object will be created by calling it. +* +* @method Phaser.GlobalSceneManager#add +* @param {string} key - A unique key you use to reference this scene, i.e. "MainMenu", "Level1". +* @param {Phaser.Scene|object|function} scene - The scene you want to switch to. +* @param {boolean} [autoStart=false] - If true the Scene will be started immediately after adding it. +*/ +var Add = function (key, sceneConfig, autoStart) +{ + if (autoStart === undefined) { autoStart = false; } + + // if not booted, then put scene into a holding pattern + if (!this.game.isBooted) + { + this._pending.push({ + index: this._pending.length, + key: key, + scene: sceneConfig, + autoStart: autoStart + }); + + // console.log('GlobalSceneManager not yet booted, adding to list', this._pending.length); + + return; + } + + // var ok = key; + key = this.getKey(key, sceneConfig); + + // console.group('GlobalSceneManager.add'); + // console.log('add key:', ok); + // console.log('config key:', key); + // console.log('config:', sceneConfig); + // console.log('autoStart:', autoStart); + // console.groupEnd(); + + var newScene; + + if (sceneConfig instanceof Scene) + { + // console.log('GlobalSceneManager.add from instance:', key); + + newScene = this.createSceneFromInstance(key, sceneConfig); + } + else if (typeof sceneConfig === 'object') + { + // console.log('GlobalSceneManager.add from object:', key); + + sceneConfig.key = key; + + newScene = this.createSceneFromObject(key, sceneConfig); + } + else if (typeof sceneConfig === 'function') + { + // console.log('GlobalSceneManager.add from function:', key); + + newScene = this.createSceneFromFunction(key, sceneConfig); + } + + // Replace key in case the scene changed it + key = newScene.sys.settings.key; + + // console.log('replaced key', key); + + this.keys[key] = newScene; + + this.scenes.push(newScene); + + if (autoStart || newScene.sys.settings.active) + { + if (this.game.isBooted) + { + this.start(key); + } + else + { + this._start.push(key); + } + } + + return newScene; +}; + +module.exports = Add; diff --git a/v3/src/state/components/Boot.js b/v3/src/scene/components/Boot.js similarity index 83% rename from v3/src/state/components/Boot.js rename to v3/src/scene/components/Boot.js index 77758cb25..bf8a05e04 100644 --- a/v3/src/state/components/Boot.js +++ b/v3/src/scene/components/Boot.js @@ -2,7 +2,7 @@ * The Boot handler is called by Phaser.Game when it first starts up. * The renderer is available by now. * -* @method Phaser.GlobalStateManager#boot +* @method Phaser.GlobalSceneManager#boot * @private */ var Boot = function () @@ -14,7 +14,7 @@ var Boot = function () { entry = this._pending[i]; - this.add(entry.key, entry.state, entry.autoStart); + this.add(entry.key, entry.scene, entry.autoStart); } for (i = 0; i < this._start.length; i++) diff --git a/v3/src/state/components/BootState.js b/v3/src/scene/components/BootScene.js similarity index 57% rename from v3/src/state/components/BootState.js rename to v3/src/scene/components/BootScene.js index a4ee593a3..79b4218b3 100644 --- a/v3/src/state/components/BootState.js +++ b/v3/src/scene/components/BootScene.js @@ -1,24 +1,24 @@ -var BootState = function (state) +var BootScene = function (scene) { - // console.log('bootState', state.sys.settings.key); + // console.log('bootScene', scene.sys.settings.key); - if (state.init) + if (scene.init) { - state.init.call(state, state.sys.settings.data); + scene.init.call(scene, scene.sys.settings.data); } - var loader = state.sys.load; + var loader = scene.sys.load; loader.reset(); - if (state.preload) + if (scene.preload) { - state.preload(this.game); + scene.preload(this.game); // Is the loader empty? if (loader.list.size === 0) { - this.create(state); + this.create(scene); } else { @@ -32,8 +32,8 @@ var BootState = function (state) else { // No preload? Then there was nothing to load either - this.create(state); + this.create(scene); } }; -module.exports = BootState; +module.exports = BootScene; diff --git a/v3/src/state/components/BringToTop.js b/v3/src/scene/components/BringToTop.js similarity index 56% rename from v3/src/state/components/BringToTop.js rename to v3/src/scene/components/BringToTop.js index f52c6a704..7a70f54fa 100644 --- a/v3/src/state/components/BringToTop.js +++ b/v3/src/scene/components/BringToTop.js @@ -1,9 +1,9 @@ -// If the arguments are strings they are assumed to be keys, otherwise they are State objects -// You can only swap the positions of Active (rendering / updating) States. If a State is not active it cannot be moved. +// If the arguments are strings they are assumed to be keys, otherwise they are Scene objects +// You can only swap the positions of Active (rendering / updating) Scenes. If a Scene is not active it cannot be moved. -var BringToTop = function (state) +var BringToTop = function (scene) { - var index = (typeof state === 'string') ? this.getActiveStateIndexByKey(state) : this.getActiveStateIndex(state); + var index = (typeof scene === 'string') ? this.getActiveSceneIndexByKey(scene) : this.getActiveSceneIndex(scene); if (index < this.active.length) { @@ -15,7 +15,7 @@ var BringToTop = function (state) this.active[i].index = i; } - this.active.push({ index: i, state: entry[0].state }); + this.active.push({ index: i, scene: entry[0].scene }); } }; diff --git a/v3/src/scene/components/Create.js b/v3/src/scene/components/Create.js new file mode 100644 index 000000000..4d467c946 --- /dev/null +++ b/v3/src/scene/components/Create.js @@ -0,0 +1,25 @@ +var SortScenes = require('./SortScenes'); + +var Create = function (scene) +{ + // console.log('create', scene.sys.settings.key); + // console.log(scene); + + // Insert at the correct index, or it just all goes wrong :) + + var i = this.getSceneIndex(scene); + + // console.log('create.index', scene.sys.settings.key, i); + + this.active.push({ index: i, scene: scene }); + + // Sort the 'active' array based on the index property + this.active.sort(SortScenes); + + if (scene.create) + { + scene.create.call(scene, scene.sys.settings.data); + } +}; + +module.exports = Create; diff --git a/v3/src/state/components/CreateStateDisplay.js b/v3/src/scene/components/CreateSceneDisplay.js similarity index 55% rename from v3/src/state/components/CreateStateDisplay.js rename to v3/src/scene/components/CreateSceneDisplay.js index e8c8937c8..84c873820 100644 --- a/v3/src/state/components/CreateStateDisplay.js +++ b/v3/src/scene/components/CreateSceneDisplay.js @@ -3,11 +3,11 @@ var CONST = require('../../const'); var GetContext = require('../../canvas/GetContext'); var CanvasInterpolation = require('../../dom/CanvasInterpolation'); -var CreateStateDisplay = function (state) +var CreateSceneDisplay = function (scene) { - // console.log('createStateDisplay', state.sys.settings.key); + // console.log('createSceneDisplay', scene.sys.settings.key); - var settings = state.sys.settings; + var settings = scene.sys.settings; var width = settings.width; var height = settings.height; @@ -19,23 +19,23 @@ var CreateStateDisplay = function (state) if (settings.renderToTexture) { // console.log('renderToTexture', width, height); - state.sys.canvas = CanvasPool.create(state, width, height); - state.sys.context = GetContext(state.sys.canvas); + scene.sys.canvas = CanvasPool.create(scene, width, height); + scene.sys.context = GetContext(scene.sys.canvas); } else { // console.log('using game canvas'); - // state.sys.mask = new Rectangle(0, 0, width, height); - state.sys.canvas = this.game.canvas; - state.sys.context = this.game.context; + // scene.sys.mask = new Rectangle(0, 0, width, height); + scene.sys.canvas = this.game.canvas; + scene.sys.context = this.game.context; } // Pixel Art mode? if (config.pixelArt) { - CanvasInterpolation.setCrisp(state.sys.canvas); + CanvasInterpolation.setCrisp(scene.sys.canvas); } } }; -module.exports = CreateStateDisplay; +module.exports = CreateSceneDisplay; diff --git a/v3/src/scene/components/CreateSceneFromFunction.js b/v3/src/scene/components/CreateSceneFromFunction.js new file mode 100644 index 000000000..db0f67eda --- /dev/null +++ b/v3/src/scene/components/CreateSceneFromFunction.js @@ -0,0 +1,75 @@ +var Scene = require('../Scene'); +var Systems = require('../Systems'); +var NOOP = require('../../utils/NOOP'); + +var CreateSceneFromFunction = function (key, scene) +{ + // console.log('createSceneFromFunction', key); + + var newScene = new scene(); + + if (newScene instanceof Scene) + { + // console.log('instanceof Scene'); + + var configKey = newScene.sys.settings.key; + + if (configKey !== '') + { + key = configKey; + } + + if (this.keys.hasOwnProperty(key)) + { + throw new Error('Cannot add a Scene with duplicate key: ' + key); + } + + return this.createSceneFromInstance(key, newScene); + } + else + { + newScene.sys = new Systems(newScene); + + newScene.sys.settings.key = key; + + newScene.sys.init(this.game); + + this.createSceneDisplay(newScene); + + // Default required functions + + if (!newScene.init) + { + newScene.init = NOOP; + } + + if (!newScene.preload) + { + newScene.preload = NOOP; + } + + if (!newScene.create) + { + newScene.create = NOOP; + } + + if (!newScene.shutdown) + { + newScene.shutdown = NOOP; + } + + if (!newScene.update) + { + newScene.update = NOOP; + } + + if (!newScene.render) + { + newScene.render = NOOP; + } + + return newScene; + } +}; + +module.exports = CreateSceneFromFunction; diff --git a/v3/src/scene/components/CreateSceneFromInstance.js b/v3/src/scene/components/CreateSceneFromInstance.js new file mode 100644 index 000000000..05483ed3a --- /dev/null +++ b/v3/src/scene/components/CreateSceneFromInstance.js @@ -0,0 +1,21 @@ +var CreateSceneFromInstance = function (key, newScene) +{ + var configKey = newScene.sys.settings.key; + + if (configKey !== '') + { + key = configKey; + } + else + { + newScene.sys.settings.key = key; + } + + newScene.sys.init(this.game); + + this.createSceneDisplay(newScene); + + return newScene; +}; + +module.exports = CreateSceneFromInstance; diff --git a/v3/src/scene/components/CreateSceneFromObject.js b/v3/src/scene/components/CreateSceneFromObject.js new file mode 100644 index 000000000..e00dac264 --- /dev/null +++ b/v3/src/scene/components/CreateSceneFromObject.js @@ -0,0 +1,25 @@ +var Scene = require('../Scene'); + +var CreateSceneFromObject = function (key, sceneConfig) +{ + var newScene = new Scene(sceneConfig); + + var configKey = newScene.sys.settings.key; + + if (configKey !== '') + { + key = configKey; + } + else + { + newScene.sys.settings.key = key; + } + + newScene.sys.init(this.game); + + this.createSceneDisplay(newScene); + + return this.setupCallbacks(newScene, sceneConfig); +}; + +module.exports = CreateSceneFromObject; diff --git a/v3/src/scene/components/GetActiveScene.js b/v3/src/scene/components/GetActiveScene.js new file mode 100644 index 000000000..f223d1011 --- /dev/null +++ b/v3/src/scene/components/GetActiveScene.js @@ -0,0 +1,14 @@ +var GetActiveScene = function (key) +{ + var scene = this.getScene(key); + + for (var i = 0; i < this.active.length; i++) + { + if (this.active[i].scene === scene) + { + return this.active[i]; + } + } +}; + +module.exports = GetActiveScene; diff --git a/v3/src/state/components/GetActiveStateIndex.js b/v3/src/scene/components/GetActiveSceneIndex.js similarity index 53% rename from v3/src/state/components/GetActiveStateIndex.js rename to v3/src/scene/components/GetActiveSceneIndex.js index c050c92af..8168e6e59 100644 --- a/v3/src/state/components/GetActiveStateIndex.js +++ b/v3/src/scene/components/GetActiveSceneIndex.js @@ -1,8 +1,8 @@ -var GetActiveStateIndex = function (state) +var GetActiveSceneIndex = function (scene) { for (var i = 0; i < this.active.length; i++) { - if (this.active[i].state === state) + if (this.active[i].scene === scene) { return this.active[i].index; } @@ -11,4 +11,4 @@ var GetActiveStateIndex = function (state) return -1; }; -module.exports = GetActiveStateIndex; +module.exports = GetActiveSceneIndex; diff --git a/v3/src/scene/components/GetActiveSceneIndexByKey.js b/v3/src/scene/components/GetActiveSceneIndexByKey.js new file mode 100644 index 000000000..15cfda439 --- /dev/null +++ b/v3/src/scene/components/GetActiveSceneIndexByKey.js @@ -0,0 +1,16 @@ +var GetActiveSceneIndexByKey = function (key) +{ + var scene = this.keys[key]; + + for (var i = 0; i < this.active.length; i++) + { + if (this.active[i].scene === scene) + { + return this.active[i].index; + } + } + + return -1; +}; + +module.exports = GetActiveSceneIndexByKey; diff --git a/v3/src/scene/components/GetKey.js b/v3/src/scene/components/GetKey.js new file mode 100644 index 000000000..afe3aa947 --- /dev/null +++ b/v3/src/scene/components/GetKey.js @@ -0,0 +1,33 @@ +var Scene = require('../Scene'); + +// private +var GetKey = function (key, sceneConfig) +{ + if (!key) { key = 'default'; } + + if (typeof sceneConfig === 'function') + { + return key; + } + else if (sceneConfig instanceof Scene) + { + key = sceneConfig.sys.settings.key; + } + else if (typeof sceneConfig === 'object' && sceneConfig.hasOwnProperty('key')) + { + key = sceneConfig.key; + } + + // By this point it's either 'default' or extracted from the Scene + + if (this.keys.hasOwnProperty(key)) + { + throw new Error('Cannot add a Scene with duplicate key: ' + key); + } + else + { + return key; + } +}; + +module.exports = GetKey; diff --git a/v3/src/scene/components/GetScene.js b/v3/src/scene/components/GetScene.js new file mode 100644 index 000000000..eb3c64104 --- /dev/null +++ b/v3/src/scene/components/GetScene.js @@ -0,0 +1,6 @@ +var GetScene = function (key) +{ + return this.keys[key]; +}; + +module.exports = GetScene; diff --git a/v3/src/scene/components/GetSceneAt.js b/v3/src/scene/components/GetSceneAt.js new file mode 100644 index 000000000..54b03110e --- /dev/null +++ b/v3/src/scene/components/GetSceneAt.js @@ -0,0 +1,11 @@ +// Get's the Active scene at the given position + +var GetSceneAt = function (index) +{ + if (this.active[index]) + { + return this.active[index].scene; + } +}; + +module.exports = GetSceneAt; diff --git a/v3/src/scene/components/GetSceneIndex.js b/v3/src/scene/components/GetSceneIndex.js new file mode 100644 index 000000000..5169af4e2 --- /dev/null +++ b/v3/src/scene/components/GetSceneIndex.js @@ -0,0 +1,6 @@ +var GetSceneIndex = function (scene) +{ + return this.scenes.indexOf(scene); +}; + +module.exports = GetSceneIndex; diff --git a/v3/src/scene/components/GetSceneIndexByKey.js b/v3/src/scene/components/GetSceneIndexByKey.js new file mode 100644 index 000000000..837446d27 --- /dev/null +++ b/v3/src/scene/components/GetSceneIndexByKey.js @@ -0,0 +1,8 @@ +var GetSceneIndexByKey = function (key) +{ + var scene = this.keys[key]; + + return this.scenes.indexOf(scene); +}; + +module.exports = GetSceneIndexByKey; diff --git a/v3/src/scene/components/IsActive.js b/v3/src/scene/components/IsActive.js new file mode 100644 index 000000000..7f2fa900e --- /dev/null +++ b/v3/src/scene/components/IsActive.js @@ -0,0 +1,8 @@ +var IsActive = function (key) +{ + var scene = this.getScene(key); + + return (scene && scene.sys.settings.active && this.active.indexOf(scene) !== -1); +}; + +module.exports = IsActive; diff --git a/v3/src/state/components/IsSleeping.js b/v3/src/scene/components/IsSleeping.js similarity index 56% rename from v3/src/state/components/IsSleeping.js rename to v3/src/scene/components/IsSleeping.js index 8c42b25e2..2d15e8e08 100644 --- a/v3/src/state/components/IsSleeping.js +++ b/v3/src/scene/components/IsSleeping.js @@ -1,10 +1,10 @@ var IsSleeping = function (key) { - var entry = this.getActiveState(key); + var entry = this.getActiveScene(key); if (entry) { - return (!entry.state.sys.settings.active && !entry.state.sys.settings.visible); + return (!entry.scene.sys.settings.active && !entry.scene.sys.settings.visible); } return false; diff --git a/v3/src/scene/components/LoadComplete.js b/v3/src/scene/components/LoadComplete.js new file mode 100644 index 000000000..dca23e149 --- /dev/null +++ b/v3/src/scene/components/LoadComplete.js @@ -0,0 +1,10 @@ +var LoadComplete = function (event) +{ + var scene = event.loader.scene; + + // console.log('loadComplete', scene.sys.settings.key); + + this.create(scene); +}; + +module.exports = LoadComplete; diff --git a/v3/src/scene/components/MoveDown.js b/v3/src/scene/components/MoveDown.js new file mode 100644 index 000000000..d2b2421fb --- /dev/null +++ b/v3/src/scene/components/MoveDown.js @@ -0,0 +1,19 @@ +// If the arguments are strings they are assumed to be keys, otherwise they are Scene objects +// You can only swap the positions of Active (rendering / updating) Scenes. If a Scene is not active it cannot be moved. + +var MoveDown = function (scene) +{ + var index = (typeof scene === 'string') ? this.getActiveSceneIndexByKey(scene) : this.getActiveSceneIndex(scene); + + if (index > 0) + { + var sceneB = this.getSceneAt(index - 1); + + if (sceneB) + { + this.swapPosition(scene, sceneB); + } + } +}; + +module.exports = MoveDown; diff --git a/v3/src/scene/components/MoveUp.js b/v3/src/scene/components/MoveUp.js new file mode 100644 index 000000000..86377a337 --- /dev/null +++ b/v3/src/scene/components/MoveUp.js @@ -0,0 +1,19 @@ +// If the arguments are strings they are assumed to be keys, otherwise they are Scene objects +// You can only swap the positions of Active (rendering / updating) Scenes. If a Scene is not active it cannot be moved. + +var MoveUp = function (scene) +{ + var index = (typeof scene === 'string') ? this.getActiveSceneIndexByKey(scene) : this.getActiveSceneIndex(scene); + + if (index !== -1 && index < this.active.length - 1) + { + var sceneB = this.getSceneAt(index + 1); + + if (sceneB) + { + this.swapPosition(scene, sceneB); + } + } +}; + +module.exports = MoveUp; diff --git a/v3/src/state/components/Pause.js b/v3/src/scene/components/Pause.js similarity index 53% rename from v3/src/state/components/Pause.js rename to v3/src/scene/components/Pause.js index c03d3324b..5f51963fb 100644 --- a/v3/src/state/components/Pause.js +++ b/v3/src/scene/components/Pause.js @@ -1,10 +1,10 @@ var Pause = function (key) { - var entry = this.getActiveState(key); + var entry = this.getActiveScene(key); if (entry) { - entry.state.sys.pause(); + entry.scene.sys.pause(); } }; diff --git a/v3/src/scene/components/PayloadComplete.js b/v3/src/scene/components/PayloadComplete.js new file mode 100644 index 000000000..39c9d9732 --- /dev/null +++ b/v3/src/scene/components/PayloadComplete.js @@ -0,0 +1,10 @@ +var PayloadComplete = function (event) +{ + var scene = event.loader.scene; + + // console.log('payloadComplete', scene.sys.settings.key); + + this.bootScene(scene); +}; + +module.exports = PayloadComplete; diff --git a/v3/src/state/components/Resume.js b/v3/src/scene/components/Resume.js similarity index 53% rename from v3/src/state/components/Resume.js rename to v3/src/scene/components/Resume.js index 5f04b66ba..a4b898bd4 100644 --- a/v3/src/state/components/Resume.js +++ b/v3/src/scene/components/Resume.js @@ -1,10 +1,10 @@ var Resume = function (key) { - var entry = this.getActiveState(key); + var entry = this.getActiveScene(key); if (entry) { - entry.state.sys.resume(); + entry.scene.sys.resume(); } }; diff --git a/v3/src/state/components/SendToBack.js b/v3/src/scene/components/SendToBack.js similarity index 54% rename from v3/src/state/components/SendToBack.js rename to v3/src/scene/components/SendToBack.js index a55c8ee38..c456c06a5 100644 --- a/v3/src/state/components/SendToBack.js +++ b/v3/src/scene/components/SendToBack.js @@ -1,15 +1,15 @@ -// If the arguments are strings they are assumed to be keys, otherwise they are State objects -// You can only swap the positions of Active (rendering / updating) States. If a State is not active it cannot be moved. +// If the arguments are strings they are assumed to be keys, otherwise they are Scene objects +// You can only swap the positions of Active (rendering / updating) Scenes. If a Scene is not active it cannot be moved. -var SendToBack = function (state) +var SendToBack = function (scene) { - var index = (typeof state === 'string') ? this.getActiveStateIndexByKey(state) : this.getActiveStateIndex(state); + var index = (typeof scene === 'string') ? this.getActiveSceneIndexByKey(scene) : this.getActiveSceneIndex(scene); if (index > 0) { var entry = this.active.splice(index, 1); - this.active.unshift({ index: 0, state: entry[0].state }); + this.active.unshift({ index: 0, scene: entry[0].scene }); for (var i = 0; i < this.active.length; i++) { diff --git a/v3/src/scene/components/SetupCallbacks.js b/v3/src/scene/components/SetupCallbacks.js new file mode 100644 index 000000000..7feda6bf1 --- /dev/null +++ b/v3/src/scene/components/SetupCallbacks.js @@ -0,0 +1,23 @@ +var GetValue = require('../../utils/object/GetValue'); +var NOOP = require('../../utils/NOOP'); + +var SetupCallbacks = function (scene, sceneConfig) +{ + if (sceneConfig === undefined) { sceneConfig = scene; } + + // Extract callbacks or set NOOP + + scene.init = GetValue(sceneConfig, 'init', NOOP); + scene.preload = GetValue(sceneConfig, 'preload', NOOP); + scene.create = GetValue(sceneConfig, 'create', NOOP); + scene.shutdown = GetValue(sceneConfig, 'shutdown', NOOP); + + // Game Loop level callbacks + + scene.update = GetValue(sceneConfig, 'update', NOOP); + scene.render = GetValue(sceneConfig, 'render', NOOP); + + return scene; +}; + +module.exports = SetupCallbacks; diff --git a/v3/src/state/components/Sleep.js b/v3/src/scene/components/Sleep.js similarity index 53% rename from v3/src/state/components/Sleep.js rename to v3/src/scene/components/Sleep.js index cef29c136..44c39d215 100644 --- a/v3/src/state/components/Sleep.js +++ b/v3/src/scene/components/Sleep.js @@ -1,10 +1,10 @@ var Sleep = function (key) { - var entry = this.getActiveState(key); + var entry = this.getActiveScene(key); if (entry) { - entry.state.sys.sleep(); + entry.scene.sys.sleep(); } }; diff --git a/v3/src/scene/components/SortScenes.js b/v3/src/scene/components/SortScenes.js new file mode 100644 index 000000000..11c3a67e0 --- /dev/null +++ b/v3/src/scene/components/SortScenes.js @@ -0,0 +1,20 @@ +var SortScenes = function (sceneA, sceneB) +{ + // console.log('sortScenes', sceneA.scene.sys.settings.key, sceneA.index, sceneB.scene.sys.settings.key, sceneB.index); + + // Sort descending + if (sceneA.index < sceneB.index) + { + return -1; + } + else if (sceneA.index > sceneB.index) + { + return 1; + } + else + { + return 0; + } +}; + +module.exports = SortScenes; diff --git a/v3/src/state/components/Start.js b/v3/src/scene/components/Start.js similarity index 67% rename from v3/src/state/components/Start.js rename to v3/src/scene/components/Start.js index 3b40b5b0a..508ddd71a 100644 --- a/v3/src/state/components/Start.js +++ b/v3/src/scene/components/Start.js @@ -5,10 +5,10 @@ var Start = function (key, data) // console.log('start:', key); // console.dir(data); - // if not booted, then put state into a holding pattern + // if not booted, then put scene into a holding pattern if (!this.game.isBooted) { - // console.log('GlobalStateManager not yet booted, setting autoStart on pending list'); + // console.log('GlobalSceneManager not yet booted, setting autoStart on pending list'); for (var i = 0; i < this._pending.length; i++) { @@ -24,11 +24,11 @@ var Start = function (key, data) return; } - var state = this.getState(key); + var scene = this.getScene(key); - // console.log(state); + // console.log(scene); - if (state) + if (scene) { // Already started? Nothing more to do here ... if (this.isActive(key)) @@ -36,16 +36,16 @@ var Start = function (key, data) return; } - state.sys.start(data); + scene.sys.start(data); - var loader = state.sys.load; + var loader = scene.sys.load; // Files payload? - if (loader && Array.isArray(state.sys.settings.files)) + if (loader && Array.isArray(scene.sys.settings.files)) { loader.reset(); - if (loader.loadArray(state.sys.settings.files)) + if (loader.loadArray(scene.sys.settings.files)) { loader.events.once('LOADER_COMPLETE_EVENT', this.payloadComplete.bind(this)); @@ -53,12 +53,12 @@ var Start = function (key, data) } else { - this.bootState(state); + this.bootScene(scene); } } else { - this.bootState(state); + this.bootScene(scene); } } }; diff --git a/v3/src/state/components/Stop.js b/v3/src/scene/components/Stop.js similarity index 61% rename from v3/src/state/components/Stop.js rename to v3/src/scene/components/Stop.js index 2da991beb..c1339319e 100644 --- a/v3/src/state/components/Stop.js +++ b/v3/src/scene/components/Stop.js @@ -1,12 +1,12 @@ -var SortStates = require('./SortStates'); +var SortScenes = require('./SortScenes'); var Stop = function (key) { - var entry = this.getActiveState(key); + var entry = this.getActiveScene(key); if (entry) { - entry.state.sys.shutdown(); + entry.scene.sys.shutdown(); // Remove from the active list var index = this.active.indexOf(entry); @@ -15,7 +15,7 @@ var Stop = function (key) { this.active.splice(index, 1); - this.active.sort(SortStates); + this.active.sort(SortScenes); } } }; diff --git a/v3/src/state/components/Swap.js b/v3/src/scene/components/Swap.js similarity index 100% rename from v3/src/state/components/Swap.js rename to v3/src/scene/components/Swap.js diff --git a/v3/src/scene/components/SwapPosition.js b/v3/src/scene/components/SwapPosition.js new file mode 100644 index 000000000..42c37a7a9 --- /dev/null +++ b/v3/src/scene/components/SwapPosition.js @@ -0,0 +1,25 @@ +var SortScenes = require('./SortScenes'); + +// If the arguments are strings they are assumed to be keys, otherwise they are Scene objects +// You can only swap the positions of Active (rendering / updating) Scenes. If a Scene is not active it cannot be moved. + +var SwapPosition = function (scene1, scene2) +{ + if (scene1 === scene2) + { + return; + } + + var index1 = (typeof scene1 === 'string') ? this.getActiveSceneIndexByKey(scene1) : this.getActiveSceneIndex(scene1); + var index2 = (typeof scene2 === 'string') ? this.getActiveSceneIndexByKey(scene2) : this.getActiveSceneIndex(scene2); + + if (index1 !== -1 && index2 !== -1) + { + this.active[index1].index = index2; + this.active[index2].index = index1; + + this.active.sort(SortScenes); + } +}; + +module.exports = SwapPosition; diff --git a/v3/src/state/components/Wake.js b/v3/src/scene/components/Wake.js similarity index 52% rename from v3/src/state/components/Wake.js rename to v3/src/scene/components/Wake.js index 76c6ea2f4..698b32911 100644 --- a/v3/src/state/components/Wake.js +++ b/v3/src/scene/components/Wake.js @@ -1,10 +1,10 @@ var Wake = function (key) { - var entry = this.getActiveState(key); + var entry = this.getActiveScene(key); if (entry) { - entry.state.sys.wake(); + entry.scene.sys.wake(); } }; diff --git a/v3/src/state/components/index.js b/v3/src/scene/components/index.js similarity index 53% rename from v3/src/state/components/index.js rename to v3/src/scene/components/index.js index 7ea68e1c7..c91289c71 100644 --- a/v3/src/state/components/index.js +++ b/v3/src/scene/components/index.js @@ -2,21 +2,21 @@ module.exports = { Add: require('./Add'), Boot: require('./Boot'), - BootState: require('./BootState'), + BootScene: require('./BootScene'), BringToTop: require('./BringToTop'), Create: require('./Create'), - CreateStateDisplay: require('./CreateStateDisplay'), - CreateStateFromFunction: require('./CreateStateFromFunction'), - CreateStateFromInstance: require('./CreateStateFromInstance'), - CreateStateFromObject: require('./CreateStateFromObject'), - GetActiveState: require('./GetActiveState'), - GetActiveStateIndex: require('./GetActiveStateIndex'), - GetActiveStateIndexByKey: require('./GetActiveStateIndexByKey'), + CreateSceneDisplay: require('./CreateSceneDisplay'), + CreateSceneFromFunction: require('./CreateSceneFromFunction'), + CreateSceneFromInstance: require('./CreateSceneFromInstance'), + CreateSceneFromObject: require('./CreateSceneFromObject'), + GetActiveScene: require('./GetActiveScene'), + GetActiveSceneIndex: require('./GetActiveSceneIndex'), + GetActiveSceneIndexByKey: require('./GetActiveSceneIndexByKey'), GetKey: require('./GetKey'), - GetState: require('./GetState'), - GetStateAt: require('./GetStateAt'), - GetStateIndex: require('./GetStateIndex'), - GetStateIndexByKey: require('./GetStateIndexByKey'), + GetScene: require('./GetScene'), + GetSceneAt: require('./GetSceneAt'), + GetSceneIndex: require('./GetSceneIndex'), + GetSceneIndexByKey: require('./GetSceneIndexByKey'), IsActive: require('./IsActive'), IsSleeping: require('./IsSleeping'), LoadComplete: require('./LoadComplete'), @@ -28,7 +28,7 @@ module.exports = { SendToBack: require('./SendToBack'), SetupCallbacks: require('./SetupCallbacks'), Sleep: require('./Sleep'), - SortStates: require('./SortStates'), + SortScenes: require('./SortScenes'), Start: require('./Start'), Stop: require('./Stop'), Swap: require('./Swap'), diff --git a/v3/src/state/const.js b/v3/src/scene/const.js similarity index 100% rename from v3/src/state/const.js rename to v3/src/scene/const.js diff --git a/v3/src/state/components/Add.js b/v3/src/state/components/Add.js deleted file mode 100644 index 500232843..000000000 --- a/v3/src/state/components/Add.js +++ /dev/null @@ -1,89 +0,0 @@ -var State = require('../State'); - -/** -* Adds a new State into the GlobalStateManager. You must give each State a unique key by which you'll identify it. -* The State can be either a Phaser.State object (or an object that extends it), a plain JavaScript object or a function. -* If a function is given a new state object will be created by calling it. -* -* @method Phaser.GlobalStateManager#add -* @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1". -* @param {Phaser.State|object|function} state - The state you want to switch to. -* @param {boolean} [autoStart=false] - If true the State will be started immediately after adding it. -*/ -var Add = function (key, stateConfig, autoStart) -{ - if (autoStart === undefined) { autoStart = false; } - - // if not booted, then put state into a holding pattern - if (!this.game.isBooted) - { - this._pending.push({ - index: this._pending.length, - key: key, - state: stateConfig, - autoStart: autoStart - }); - - // console.log('GlobalStateManager not yet booted, adding to list', this._pending.length); - - return; - } - - // var ok = key; - key = this.getKey(key, stateConfig); - - // console.group('GlobalStateManager.add'); - // console.log('add key:', ok); - // console.log('config key:', key); - // console.log('config:', stateConfig); - // console.log('autoStart:', autoStart); - // console.groupEnd(); - - var newState; - - if (stateConfig instanceof State) - { - // console.log('GlobalStateManager.add from instance:', key); - - newState = this.createStateFromInstance(key, stateConfig); - } - else if (typeof stateConfig === 'object') - { - // console.log('GlobalStateManager.add from object:', key); - - stateConfig.key = key; - - newState = this.createStateFromObject(key, stateConfig); - } - else if (typeof stateConfig === 'function') - { - // console.log('GlobalStateManager.add from function:', key); - - newState = this.createStateFromFunction(key, stateConfig); - } - - // Replace key in case the state changed it - key = newState.sys.settings.key; - - // console.log('replaced key', key); - - this.keys[key] = newState; - - this.states.push(newState); - - if (autoStart || newState.sys.settings.active) - { - if (this.game.isBooted) - { - this.start(key); - } - else - { - this._start.push(key); - } - } - - return newState; -}; - -module.exports = Add; diff --git a/v3/src/state/components/Create.js b/v3/src/state/components/Create.js deleted file mode 100644 index 53cd60698..000000000 --- a/v3/src/state/components/Create.js +++ /dev/null @@ -1,25 +0,0 @@ -var SortStates = require('./SortStates'); - -var Create = function (state) -{ - // console.log('create', state.sys.settings.key); - // console.log(state); - - // Insert at the correct index, or it just all goes wrong :) - - var i = this.getStateIndex(state); - - // console.log('create.index', state.sys.settings.key, i); - - this.active.push({ index: i, state: state }); - - // Sort the 'active' array based on the index property - this.active.sort(SortStates); - - if (state.create) - { - state.create.call(state, state.sys.settings.data); - } -}; - -module.exports = Create; diff --git a/v3/src/state/components/CreateStateFromFunction.js b/v3/src/state/components/CreateStateFromFunction.js deleted file mode 100644 index 30eb9521a..000000000 --- a/v3/src/state/components/CreateStateFromFunction.js +++ /dev/null @@ -1,75 +0,0 @@ -var State = require('../State'); -var Systems = require('../Systems'); -var NOOP = require('../../utils/NOOP'); - -var CreateStateFromFunction = function (key, state) -{ - // console.log('createStateFromFunction', key); - - var newState = new state(); - - if (newState instanceof State) - { - // console.log('instanceof State'); - - var configKey = newState.sys.settings.key; - - if (configKey !== '') - { - key = configKey; - } - - if (this.keys.hasOwnProperty(key)) - { - throw new Error('Cannot add a State with duplicate key: ' + key); - } - - return this.createStateFromInstance(key, newState); - } - else - { - newState.sys = new Systems(newState); - - newState.sys.settings.key = key; - - newState.sys.init(this.game); - - this.createStateDisplay(newState); - - // Default required functions - - if (!newState.init) - { - newState.init = NOOP; - } - - if (!newState.preload) - { - newState.preload = NOOP; - } - - if (!newState.create) - { - newState.create = NOOP; - } - - if (!newState.shutdown) - { - newState.shutdown = NOOP; - } - - if (!newState.update) - { - newState.update = NOOP; - } - - if (!newState.render) - { - newState.render = NOOP; - } - - return newState; - } -}; - -module.exports = CreateStateFromFunction; diff --git a/v3/src/state/components/CreateStateFromInstance.js b/v3/src/state/components/CreateStateFromInstance.js deleted file mode 100644 index c078f89a2..000000000 --- a/v3/src/state/components/CreateStateFromInstance.js +++ /dev/null @@ -1,21 +0,0 @@ -var CreateStateFromInstance = function (key, newState) -{ - var configKey = newState.sys.settings.key; - - if (configKey !== '') - { - key = configKey; - } - else - { - newState.sys.settings.key = key; - } - - newState.sys.init(this.game); - - this.createStateDisplay(newState); - - return newState; -}; - -module.exports = CreateStateFromInstance; diff --git a/v3/src/state/components/CreateStateFromObject.js b/v3/src/state/components/CreateStateFromObject.js deleted file mode 100644 index 26b10afbc..000000000 --- a/v3/src/state/components/CreateStateFromObject.js +++ /dev/null @@ -1,25 +0,0 @@ -var State = require('../State'); - -var CreateStateFromObject = function (key, stateConfig) -{ - var newState = new State(stateConfig); - - var configKey = newState.sys.settings.key; - - if (configKey !== '') - { - key = configKey; - } - else - { - newState.sys.settings.key = key; - } - - newState.sys.init(this.game); - - this.createStateDisplay(newState); - - return this.setupCallbacks(newState, stateConfig); -}; - -module.exports = CreateStateFromObject; diff --git a/v3/src/state/components/GetActiveState.js b/v3/src/state/components/GetActiveState.js deleted file mode 100644 index 845750de1..000000000 --- a/v3/src/state/components/GetActiveState.js +++ /dev/null @@ -1,14 +0,0 @@ -var GetActiveState = function (key) -{ - var state = this.getState(key); - - for (var i = 0; i < this.active.length; i++) - { - if (this.active[i].state === state) - { - return this.active[i]; - } - } -}; - -module.exports = GetActiveState; diff --git a/v3/src/state/components/GetActiveStateIndexByKey.js b/v3/src/state/components/GetActiveStateIndexByKey.js deleted file mode 100644 index 514c339ac..000000000 --- a/v3/src/state/components/GetActiveStateIndexByKey.js +++ /dev/null @@ -1,16 +0,0 @@ -var GetActiveStateIndexByKey = function (key) -{ - var state = this.keys[key]; - - for (var i = 0; i < this.active.length; i++) - { - if (this.active[i].state === state) - { - return this.active[i].index; - } - } - - return -1; -}; - -module.exports = GetActiveStateIndexByKey; diff --git a/v3/src/state/components/GetKey.js b/v3/src/state/components/GetKey.js deleted file mode 100644 index d9064de74..000000000 --- a/v3/src/state/components/GetKey.js +++ /dev/null @@ -1,33 +0,0 @@ -var State = require('../State'); - -// private -var GetKey = function (key, stateConfig) -{ - if (!key) { key = 'default'; } - - if (typeof stateConfig === 'function') - { - return key; - } - else if (stateConfig instanceof State) - { - key = stateConfig.sys.settings.key; - } - else if (typeof stateConfig === 'object' && stateConfig.hasOwnProperty('key')) - { - key = stateConfig.key; - } - - // By this point it's either 'default' or extracted from the State - - if (this.keys.hasOwnProperty(key)) - { - throw new Error('Cannot add a State with duplicate key: ' + key); - } - else - { - return key; - } -}; - -module.exports = GetKey; diff --git a/v3/src/state/components/GetState.js b/v3/src/state/components/GetState.js deleted file mode 100644 index f950fdc6d..000000000 --- a/v3/src/state/components/GetState.js +++ /dev/null @@ -1,6 +0,0 @@ -var GetState = function (key) -{ - return this.keys[key]; -}; - -module.exports = GetState; diff --git a/v3/src/state/components/GetStateAt.js b/v3/src/state/components/GetStateAt.js deleted file mode 100644 index da041c501..000000000 --- a/v3/src/state/components/GetStateAt.js +++ /dev/null @@ -1,11 +0,0 @@ -// Get's the Active state at the given position - -var GetStateAt = function (index) -{ - if (this.active[index]) - { - return this.active[index].state; - } -}; - -module.exports = GetStateAt; diff --git a/v3/src/state/components/GetStateIndex.js b/v3/src/state/components/GetStateIndex.js deleted file mode 100644 index 796a3cd99..000000000 --- a/v3/src/state/components/GetStateIndex.js +++ /dev/null @@ -1,6 +0,0 @@ -var GetStateIndex = function (state) -{ - return this.states.indexOf(state); -}; - -module.exports = GetStateIndex; diff --git a/v3/src/state/components/GetStateIndexByKey.js b/v3/src/state/components/GetStateIndexByKey.js deleted file mode 100644 index ffc9fe83d..000000000 --- a/v3/src/state/components/GetStateIndexByKey.js +++ /dev/null @@ -1,8 +0,0 @@ -var GetStateIndexByKey = function (key) -{ - var state = this.keys[key]; - - return this.states.indexOf(state); -}; - -module.exports = GetStateIndexByKey; diff --git a/v3/src/state/components/IsActive.js b/v3/src/state/components/IsActive.js deleted file mode 100644 index aa7f812e3..000000000 --- a/v3/src/state/components/IsActive.js +++ /dev/null @@ -1,8 +0,0 @@ -var IsActive = function (key) -{ - var state = this.getState(key); - - return (state && state.sys.settings.active && this.active.indexOf(state) !== -1); -}; - -module.exports = IsActive; diff --git a/v3/src/state/components/LoadComplete.js b/v3/src/state/components/LoadComplete.js deleted file mode 100644 index a71318139..000000000 --- a/v3/src/state/components/LoadComplete.js +++ /dev/null @@ -1,10 +0,0 @@ -var LoadComplete = function (event) -{ - var state = event.loader.state; - - // console.log('loadComplete', state.sys.settings.key); - - this.create(state); -}; - -module.exports = LoadComplete; diff --git a/v3/src/state/components/MoveDown.js b/v3/src/state/components/MoveDown.js deleted file mode 100644 index ce4e126eb..000000000 --- a/v3/src/state/components/MoveDown.js +++ /dev/null @@ -1,19 +0,0 @@ -// If the arguments are strings they are assumed to be keys, otherwise they are State objects -// You can only swap the positions of Active (rendering / updating) States. If a State is not active it cannot be moved. - -var MoveDown = function (state) -{ - var index = (typeof state === 'string') ? this.getActiveStateIndexByKey(state) : this.getActiveStateIndex(state); - - if (index > 0) - { - var stateB = this.getStateAt(index - 1); - - if (stateB) - { - this.swapPosition(state, stateB); - } - } -}; - -module.exports = MoveDown; diff --git a/v3/src/state/components/MoveUp.js b/v3/src/state/components/MoveUp.js deleted file mode 100644 index db4295817..000000000 --- a/v3/src/state/components/MoveUp.js +++ /dev/null @@ -1,19 +0,0 @@ -// If the arguments are strings they are assumed to be keys, otherwise they are State objects -// You can only swap the positions of Active (rendering / updating) States. If a State is not active it cannot be moved. - -var MoveUp = function (state) -{ - var index = (typeof state === 'string') ? this.getActiveStateIndexByKey(state) : this.getActiveStateIndex(state); - - if (index !== -1 && index < this.active.length - 1) - { - var stateB = this.getStateAt(index + 1); - - if (stateB) - { - this.swapPosition(state, stateB); - } - } -}; - -module.exports = MoveUp; diff --git a/v3/src/state/components/PayloadComplete.js b/v3/src/state/components/PayloadComplete.js deleted file mode 100644 index 944b98548..000000000 --- a/v3/src/state/components/PayloadComplete.js +++ /dev/null @@ -1,10 +0,0 @@ -var PayloadComplete = function (event) -{ - var state = event.loader.state; - - // console.log('payloadComplete', state.sys.settings.key); - - this.bootState(state); -}; - -module.exports = PayloadComplete; diff --git a/v3/src/state/components/SetupCallbacks.js b/v3/src/state/components/SetupCallbacks.js deleted file mode 100644 index 04268722d..000000000 --- a/v3/src/state/components/SetupCallbacks.js +++ /dev/null @@ -1,23 +0,0 @@ -var GetValue = require('../../utils/object/GetValue'); -var NOOP = require('../../utils/NOOP'); - -var SetupCallbacks = function (state, stateConfig) -{ - if (stateConfig === undefined) { stateConfig = state; } - - // Extract callbacks or set NOOP - - state.init = GetValue(stateConfig, 'init', NOOP); - state.preload = GetValue(stateConfig, 'preload', NOOP); - state.create = GetValue(stateConfig, 'create', NOOP); - state.shutdown = GetValue(stateConfig, 'shutdown', NOOP); - - // Game Loop level callbacks - - state.update = GetValue(stateConfig, 'update', NOOP); - state.render = GetValue(stateConfig, 'render', NOOP); - - return state; -}; - -module.exports = SetupCallbacks; diff --git a/v3/src/state/components/SortStates.js b/v3/src/state/components/SortStates.js deleted file mode 100644 index ba5c83ca4..000000000 --- a/v3/src/state/components/SortStates.js +++ /dev/null @@ -1,20 +0,0 @@ -var SortStates = function (stateA, stateB) -{ - // console.log('sortStates', stateA.state.sys.settings.key, stateA.index, stateB.state.sys.settings.key, stateB.index); - - // Sort descending - if (stateA.index < stateB.index) - { - return -1; - } - else if (stateA.index > stateB.index) - { - return 1; - } - else - { - return 0; - } -}; - -module.exports = SortStates; diff --git a/v3/src/state/components/SwapPosition.js b/v3/src/state/components/SwapPosition.js deleted file mode 100644 index eaa2452ff..000000000 --- a/v3/src/state/components/SwapPosition.js +++ /dev/null @@ -1,25 +0,0 @@ -var SortStates = require('./SortStates'); - -// If the arguments are strings they are assumed to be keys, otherwise they are State objects -// You can only swap the positions of Active (rendering / updating) States. If a State is not active it cannot be moved. - -var SwapPosition = function (state1, state2) -{ - if (state1 === state2) - { - return; - } - - var index1 = (typeof state1 === 'string') ? this.getActiveStateIndexByKey(state1) : this.getActiveStateIndex(state1); - var index2 = (typeof state2 === 'string') ? this.getActiveStateIndexByKey(state2) : this.getActiveStateIndex(state2); - - if (index1 !== -1 && index2 !== -1) - { - this.active[index1].index = index2; - this.active[index2].index = index1; - - this.active.sort(SortStates); - } -}; - -module.exports = SwapPosition; diff --git a/v3/src/textures/Frame.js b/v3/src/textures/Frame.js index 4bc3cbab7..2e9104aa6 100644 --- a/v3/src/textures/Frame.js +++ b/v3/src/textures/Frame.js @@ -232,7 +232,7 @@ var Frame = new Class({ uvs.x3 = (this.cutX + this.cutHeight) / tw; uvs.y3 = (this.cutY + this.cutWidth) / th; - uvs.x2 = this.cutX / tw; + uvs.x2 = this.cutX / tw; uvs.y2 = (this.cutY + this.cutWidth) / th; uvs.x1 = this.cutX / tw; diff --git a/v3/src/textures/TextureManager.js b/v3/src/textures/TextureManager.js index a780ad36c..95ce1d968 100644 --- a/v3/src/textures/TextureManager.js +++ b/v3/src/textures/TextureManager.js @@ -12,7 +12,7 @@ var Texture = require('./Texture'); * * Sprites and other Game Objects get the texture data they need from the TextureManager. * -* Access it via `state.textures`. +* Access it via `scene.textures`. * * @class Phaser.TextureManager * @constructor diff --git a/v3/src/time/Clock.js b/v3/src/time/Clock.js index 2def2a876..60fe3b123 100644 --- a/v3/src/time/Clock.js +++ b/v3/src/time/Clock.js @@ -5,9 +5,9 @@ var Clock = new Class({ initialize: - function Clock (state) + function Clock (scene) { - this.state = state; + this.scene = scene; this.now = Date.now(); @@ -147,7 +147,7 @@ var Clock = new Class({ } }, - // State that owns this Clock is shutting down + // Scene that owns this Clock is shutting down shutdown: function () { var i; @@ -177,7 +177,7 @@ var Clock = new Class({ { this.shutdown(); - this.state = undefined; + this.scene = undefined; } }); diff --git a/v3/src/tween/TweenManager.js b/v3/src/tween/TweenManager.js index a6fed0bd6..0cd1dfa81 100644 --- a/v3/src/tween/TweenManager.js +++ b/v3/src/tween/TweenManager.js @@ -7,15 +7,15 @@ var TweenManager = new Class({ initialize: - function TweenManager (state) + function TweenManager (scene) { - // The State the Tween Manager belongs to (tweens are State specific, not Game global) - this.state = state; + // The Scene the Tween Manager belongs to (tweens are Scene specific, not Game global) + this.scene = scene; /** * @property {EventDispatcher} events - Global / Global Game System Events */ - this.events = new EventDispatcher(); // should use State event dispatcher? + this.events = new EventDispatcher(); // should use Scene event dispatcher? // TODO: // Add _pool array and make the queue re-use objects within it. @@ -31,7 +31,7 @@ var TweenManager = new Class({ boot: function () { - // State is starting up + // Scene is starting up }, add: function (config) @@ -215,7 +215,7 @@ var TweenManager = new Class({ } }, - // State that owns this manager is shutting down + // Scene that owns this manager is shutting down shutdown: function () { },