diff --git a/Phaser/Game.ts b/Phaser/Game.ts index 86e3e660..62fab329 100644 --- a/Phaser/Game.ts +++ b/Phaser/Game.ts @@ -17,17 +17,17 @@ /// /// /// -/// +/// /// /// /// /// -/// +/// /// /// /// /// -/// +/// /** * Phaser - Game @@ -71,13 +71,10 @@ module Phaser { if (document.readyState === 'complete' || document.readyState === 'interactive') { - //setTimeout(() => this.boot(parent, width, height)); setTimeout(() => Phaser.GAMES[this.id].boot(parent, width, height)); } else { - //document.addEventListener('DOMContentLoaded', () => this.boot(parent, width, height), false); - //window.addEventListener('load', () => this.boot(parent, width, height), false); document.addEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot(parent, width, height), false); window.addEventListener('load', Phaser.GAMES[this.id].boot(parent, width, height), false); } @@ -116,22 +113,10 @@ module Phaser { private _pendingState = null; /** - * Plugin loop pointer - * @type {number} + * The PluginManager for the Game + * @type {PluginManager} */ - private _p: number; - - /** - * Plugins array counter - * @type {number} - */ - private _pluginsLength: number; - - /** - * An Array of Phaser Plugins - * @type {Array} - */ - public plugins: Phaser.IPlugin[]; + public plugins: PluginManager; /** * The current State object (defaults to null) @@ -214,7 +199,7 @@ module Phaser { * Reference to the input manager * @type {Input} */ - public input: Input; + public input: InputManager; /** * Reference to the assets loader. @@ -250,7 +235,7 @@ module Phaser { * Reference to game clock. * @type {Time} */ - public time: Time; + public time: TimeManager; /** * Reference to the tween manager. @@ -315,7 +300,6 @@ module Phaser { if (!document.body) { - //window.setTimeout(() => this.boot(parent, width, height), 13); setTimeout(() => Phaser.GAMES[this.id].boot(parent, width, height), 13); } else @@ -331,12 +315,13 @@ module Phaser { this.add = new GameObjectFactory(this); this.cache = new Cache(this); this.load = new Loader(this, this.loadComplete); - this.time = new Time(this); + this.time = new TimeManager(this); this.tweens = new TweenManager(this); - this.input = new Input(this); + this.input = new InputManager(this); this.sound = new SoundManager(this); this.rnd = new RandomDataGenerator([(Date.now() * Math.random()).toString()]); this.physics = new Physics.Manager(this); + this.plugins = new PluginManager(this, this); this.setRenderer(Phaser.Types.RENDERER_CANVAS); @@ -396,30 +381,6 @@ module Phaser { } - public addPlugin(plugin) { - - // Prototype? - if (typeof plugin === 'function') - { - this.plugins.push(new plugin(this)); - } - else - { - plugin.game = this; - this.plugins.push(plugin); - } - - this._pluginsLength++; - - } - - public removePlugin(plugin: Phaser.IPlugin) { - - // TODO :) - this._pluginsLength--; - - } - /** * Called when the load has finished after init was run. */ @@ -455,25 +416,24 @@ module Phaser { } + private emptyCallback() { + // Called by onUpdateCallback etc + } + /** * Game loop method will be called when it's running. */ private loop() { - for (this._p = 0; this._p < this._pluginsLength; this._p++) - { - if (this.plugins[this._p].active) - { - this.plugins[this._p].preUpdate(); - } - } + this.plugins.preUpdate(); this.tweens.update(); this.input.update(); this.stage.update(); this.sound.update(); - this.physics.update(); + //this.physics.update(); this.world.update(); + this.plugins.update(); if (this._loadComplete && this.onUpdateCallback) { @@ -486,21 +446,8 @@ module Phaser { this.world.postUpdate(); - for (this._p = 0; this._p < this._pluginsLength; this._p++) - { - if (this.plugins[this._p].active) - { - this.plugins[this._p].postUpdate(); - } - } - - for (this._p = 0; this._p < this._pluginsLength; this._p++) - { - if (this.plugins[this._p].visible) - { - this.plugins[this._p].preRender(); - } - } + this.plugins.postUpdate(); + this.plugins.preRender(); if (this._loadComplete && this.onPreRenderCallback) { @@ -508,6 +455,7 @@ module Phaser { } this.renderer.render(); + this.plugins.render(); if (this._loadComplete && this.onRenderCallback) { @@ -518,13 +466,7 @@ module Phaser { this.onLoadRenderCallback.call(this.callbackContext); } - for (this._p = 0; this._p < this._pluginsLength; this._p++) - { - if (this.plugins[this._p].visible) - { - this.plugins[this._p].postRender(); - } - } + this.plugins.postRender(); } @@ -747,21 +689,6 @@ module Phaser { } - /** - * Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group. - * Note: Does not take the objects scrollFactor into account. All overlaps are check in world space. - * @param object1 The first GameObject or Group to check. If null the world.group is used. - * @param object2 The second GameObject or Group to check. - * @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap. - * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true. - * @param context The context in which the callbacks will be called - * @returns {boolean} true if the objects overlap, otherwise false. - */ - public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.callbackContext): bool { - //return this.world.physics.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, this.world.physics.separate, context); - return false; - } - public get camera(): Camera { return this.world.cameras.current; } diff --git a/Phaser/Phaser.csproj b/Phaser/Phaser.csproj index 3136b66f..38ac7d55 100644 --- a/Phaser/Phaser.csproj +++ b/Phaser/Phaser.csproj @@ -58,67 +58,65 @@ - + + + Animation.ts + + + + AnimationManager.ts + + Frame.ts + + + + FrameData.ts + - - - - + + + + Plugin.ts + + + PluginManager.ts + + + CSS3Filters.ts - - Debug.ts + + + + DynamicTexture.ts - - Events.ts - - - - Input.ts - - - + Texture.ts - - - - - Transform.ts - Game.ts - - - CameraFX.ts - - - - - Button.ts - - - DynamicTexture.ts - - - - Emitter.ts + + + Events.ts IGameObject.ts - - - - Tilemap.ts - + + + ScrollRegion.ts + + + + TransformManager.ts + Circle.ts @@ -134,6 +132,14 @@ Rectangle.ts + + + + InputHandler.ts + + + InputManager.ts + GameMath.ts @@ -166,14 +172,6 @@ LinkedList.ts - - - Transform.ts - - - - TransformUtils.ts - Vec2.ts @@ -182,6 +180,14 @@ Net.ts + + + ArcadeEmitter.ts + + + + ArcadeParticle.ts + ArcadePhysics.ts @@ -215,10 +221,29 @@ OrientationScreen.ts + + + Tile.ts + + + + + Tilemap.ts + + + TilemapLayer.ts + + + + + TimeManager.ts + + + Button.ts + CircleUtils.ts - ColorUtils.ts @@ -227,9 +252,6 @@ DebugUtils.ts - - PixelUtils.ts - PointUtils.ts @@ -237,9 +259,6 @@ RectangleUtils.ts - - IntersectResult.ts - Vec2Utils.ts @@ -272,18 +291,9 @@ - - Animation.ts - AnimationLoader.ts - - Frame.ts - - - FrameData.ts - Camera.ts @@ -368,11 +378,7 @@ - - - - Group.ts @@ -394,9 +400,6 @@ State.ts - - Time.ts - TweenManager.ts @@ -409,7 +412,6 @@ - @@ -418,8 +420,6 @@ - - Cache.ts diff --git a/Phaser/Stage.ts b/Phaser/Stage.ts index 38f40717..42c4bf0e 100644 --- a/Phaser/Stage.ts +++ b/Phaser/Stage.ts @@ -1,6 +1,6 @@ /// /// -/// +/// /// /// /// @@ -53,7 +53,7 @@ module Phaser { this.context = this.canvas.getContext('2d'); - this.css3 = new Phaser.Components.CSS3Filters(this.canvas); + this.css3 = new Phaser.Display.CSS3Filters(this.canvas); this.scaleMode = StageScaleMode.NO_SCALE; this.scale = new StageScaleMode(this._game, width, height); @@ -102,9 +102,9 @@ module Phaser { /** * Controls the CSS3 Filters applied to the Stages canvas object. - * @type {Phaser.Components.CSS3Filters} + * @type {Phaser.Display.CSS3Filters} */ - public css3: Phaser.Components.CSS3Filters; + public css3: Phaser.Display.CSS3Filters; /** * Bound of this stage. @@ -175,6 +175,13 @@ module Phaser { */ public disableVisibilityChange: bool = false; + /** + * An optional 'fix' for the horrendous Android stock browser bug + * https://code.google.com/p/android/issues/detail?id=39247 + * @type {boolean} + */ + public patchAndroidClearRectBug: bool = false; + /** * Stage boot */ @@ -196,10 +203,9 @@ module Phaser { this.scale.update(); - if (this.clear) + if (this.clear || (this._game.paused && this.disablePauseScreen == false)) { - // A 'fix' for the horrendous Android stock browser bug: https://code.google.com/p/android/issues/detail?id=39247 - if (this._game.device.android && this._game.device.chrome == false) + if (this.patchAndroidClearRectBug) { this.context.fillStyle = 'rgb(0,0,0)'; this.context.fillRect(0, 0, this.width, this.height); @@ -295,6 +301,7 @@ module Phaser { } this.saveCanvasValues(); + this._game.paused = true; } @@ -307,6 +314,7 @@ module Phaser { } this.restoreCanvasValues(); + this._game.paused = false; } @@ -373,11 +381,23 @@ module Phaser { this.context.lineWidth = this.lineWidth; this.context.fillStyle = this.fillStyle; + if (this.patchAndroidClearRectBug) + { + this.context.fillStyle = 'rgb(0,0,0)'; + this.context.fillRect(0, 0, this.width, this.height); + } + else + { + this.context.clearRect(0, 0, this.width, this.height); + } + } public set backgroundColor(color: string) { + this.canvas.style.backgroundColor = color; this._backgroundColor = color; + } public get backgroundColor(): string { diff --git a/Phaser/State.ts b/Phaser/State.ts index 698ef364..9cea6845 100644 --- a/Phaser/State.ts +++ b/Phaser/State.ts @@ -59,7 +59,7 @@ module Phaser { * Reference to the input manager * @type {Input} */ - public input: Input; + public input: InputManager; /** * Reference to the assets loader. @@ -89,7 +89,7 @@ module Phaser { * Reference to game clock. * @type {Time} */ - public time: Time; + public time: TimeManager; /** * Reference to the tween manager. diff --git a/Phaser/components/animation/Animation.ts b/Phaser/animation/Animation.ts similarity index 99% rename from Phaser/components/animation/Animation.ts rename to Phaser/animation/Animation.ts index 7f7bf59a..41f61a5b 100644 --- a/Phaser/components/animation/Animation.ts +++ b/Phaser/animation/Animation.ts @@ -1,4 +1,4 @@ -/// +/// /** * Phaser - Animation diff --git a/Phaser/components/animation/AnimationManager.ts b/Phaser/animation/AnimationManager.ts similarity index 98% rename from Phaser/components/animation/AnimationManager.ts rename to Phaser/animation/AnimationManager.ts index 399c8e0b..115a8b8b 100644 --- a/Phaser/components/animation/AnimationManager.ts +++ b/Phaser/animation/AnimationManager.ts @@ -1,6 +1,6 @@ -/// -/// -/// +/// +/// +/// /// /// /// diff --git a/Phaser/components/animation/Frame.ts b/Phaser/animation/Frame.ts similarity index 99% rename from Phaser/components/animation/Frame.ts rename to Phaser/animation/Frame.ts index 795dc319..1af54b27 100644 --- a/Phaser/components/animation/Frame.ts +++ b/Phaser/animation/Frame.ts @@ -1,4 +1,4 @@ -/// +/// /** * Phaser - Frame diff --git a/Phaser/components/animation/FrameData.ts b/Phaser/animation/FrameData.ts similarity index 99% rename from Phaser/components/animation/FrameData.ts rename to Phaser/animation/FrameData.ts index 5594fe12..1d1e48cf 100644 --- a/Phaser/components/animation/FrameData.ts +++ b/Phaser/animation/FrameData.ts @@ -1,4 +1,4 @@ -/// +/// /** * Phaser - FrameData diff --git a/Phaser/cameras/Camera.ts b/Phaser/cameras/Camera.ts index 4bfab567..2d7e32a8 100644 --- a/Phaser/cameras/Camera.ts +++ b/Phaser/cameras/Camera.ts @@ -2,10 +2,10 @@ /// /// /// -/// -/// -/// +/// +/// /// +/// /** * Phaser - Camera @@ -46,10 +46,10 @@ module Phaser { // The rect of the area being rendered in stage/screen coordinates this.screenView = new Rectangle(x, y, width, height); - this.fx = new CameraFX(this.game, this); + this.plugins = new PluginManager(this.game, this); - this.transform = new Phaser.Components.Transform(this); - this.texture = new Phaser.Components.Texture(this); + this.transform = new Phaser.Components.TransformManager(this); + this.texture = new Phaser.Display.Texture(this); this.texture.opaque = false; @@ -60,19 +60,25 @@ module Phaser { private _target: Sprite = null; /** - * Local private reference to Game. + * Local reference to Game. */ public game: Game; + /** + * The PluginManager for the Game + * @type {PluginManager} + */ + public plugins: PluginManager; + /** * Optional texture used in the background of the Camera. */ - public texture: Phaser.Components.Texture; + public texture: Phaser.Display.Texture; /** * The transform component. */ - public transform: Phaser.Components.Transform; + public transform: Phaser.Components.TransformManager; /** * Camera "follow" style preset: camera has no deadzone, just tracks the focus object directly. @@ -154,12 +160,6 @@ module Phaser { */ public z: number = -1; - /** - * Effects manager. - * @type {CameraFX} - */ - public fx: CameraFX; - /** * Hides an object from this Camera. Hidden objects are not rendered. * The object must implement a public cameraBlacklist property. @@ -295,7 +295,7 @@ module Phaser { this.modified = true; } - this.fx.preUpdate(); + this.plugins.preUpdate(); if (this._target !== null) { @@ -364,6 +364,8 @@ module Phaser { } } + this.plugins.update(); + } /** @@ -400,7 +402,7 @@ module Phaser { } } - this.fx.postUpdate(); + this.plugins.postUpdate(); } @@ -431,7 +433,7 @@ module Phaser { public destroy() { this.game.world.cameras.removeCamera(this.ID); - this.fx.destroy(); + this.plugins.destroy(); } public get x(): number { diff --git a/Phaser/components/camera/CameraFX.ts b/Phaser/components/camera/CameraFX.ts deleted file mode 100644 index fdd1492e..00000000 --- a/Phaser/components/camera/CameraFX.ts +++ /dev/null @@ -1,225 +0,0 @@ -/// -/// - -/** -* Phaser - CameraFX -* -* CameraFX controls all special effects applied to game Cameras. -*/ - -module Phaser { - - export class CameraFX { - - constructor(game: Game, parent) { - - this._game = game; - this._parent = parent; - this._fx = []; - - this.active = true; - this.visible = true; - - } - - /** - * The essential reference to the main game object. - */ - private _game: Game; - - /** - * A reference to the object that owns this FXManager instance. - */ - private _parent; - - /** - * The array in which we keep all of the registered FX - */ - private _fx; - - /** - * Holds the size of the _fx array - */ - private _length: number; - - /** - * Controls whether any of the FX have preUpdate, update or postUpdate called - */ - public active: bool; - - /** - * Controls whether any of the FX have preRender, render or postRender called - */ - public visible: bool; - - /** - * Adds a new FX to the FXManager. - * The effect must be an object with at least one of the following methods: preUpdate, postUpdate, preRender, render or postRender. - * A new instance of the effect will be created and a reference to Game will be passed to the object constructor. - * @param {object} effect - * @return {any} - */ - public add(effect): any { - - var result: bool = false; - var newEffect = { effect: {}, preUpdate: false, postUpdate: false, preRender: false, render: false, postRender: false }; - - if (typeof effect === 'function') - { - newEffect.effect = new effect(this._game, this._parent); - } - else - { - throw new Error("Invalid object given to Phaser.CameraFX.add"); - } - - // Check for methods now to avoid having to do this every loop - - if (typeof newEffect.effect['preUpdate'] === 'function') - { - newEffect.preUpdate = true; - result = true; - } - - if (typeof newEffect.effect['postUpdate'] === 'function') - { - newEffect.postUpdate = true; - result = true; - } - - if (typeof newEffect.effect['preRender'] === 'function') - { - newEffect.preRender = true; - result = true; - } - - if (typeof newEffect.effect['render'] === 'function') - { - newEffect.render = true; - result = true; - } - - if (typeof newEffect.effect['postRender'] === 'function') - { - newEffect.postRender = true; - result = true; - } - - if (result == true) - { - this._length = this._fx.push(newEffect); - - return newEffect.effect; - } - else - { - return result; - } - - } - - /** - * Pre-update is called at the start of the objects update cycle, before any other updates have taken place. - */ - public preUpdate() { - - if (this.active) - { - for (var i = 0; i < this._length; i++) - { - if (this._fx[i].preUpdate) - { - this._fx[i].effect.preUpdate(); - } - } - } - - } - - /** - * Post-update is called at the end of the objects update cycle, after other update logic has taken place. - */ - public postUpdate() { - - if (this.active) - { - for (var i = 0; i < this._length; i++) - { - if (this._fx[i].postUpdate) - { - this._fx[i].effect.postUpdate(); - } - } - } - - } - - /** - * Pre-render is called at the start of the object render cycle, before any transforms have taken place. - * It happens directly AFTER a canvas context.save has happened if added to a Camera. - * @param {Camera} camera - */ - public preRender(camera:Camera) { - - if (this.visible) - { - for (var i = 0; i < this._length; i++) - { - if (this._fx[i].preRender) - { - this._fx[i].effect.preRender(camera); - } - } - } - - } - - /** - * render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered. - * @param {Camera} camera - */ - public render(camera:Camera) { - - if (this.visible) - { - for (var i = 0; i < this._length; i++) - { - if (this._fx[i].preRender) - { - this._fx[i].effect.preRender(camera); - } - } - } - - } - - /** - * Post-render is called during the objects render cycle, after the children/image data has been rendered. - * It happens directly BEFORE a canvas context.restore has happened if added to a Camera. - */ - public postRender(camera:Camera) { - - if (this.visible) - { - for (var i = 0; i < this._length; i++) - { - if (this._fx[i].postRender) - { - this._fx[i].effect.postRender(camera); - } - } - } - - } - - /** - * Clear down this FXManager and null out references - */ - public destroy() { - this._game = null; - this._fx = null; - } - - } - -} diff --git a/Phaser/components/sprite/Debug.ts b/Phaser/components/sprite/Debug.ts deleted file mode 100644 index 421b5f52..00000000 --- a/Phaser/components/sprite/Debug.ts +++ /dev/null @@ -1,73 +0,0 @@ -/** -* Phaser - Components - Debug -* -* -*/ - -module Phaser.Components { - - export class Debug { - - /** - * Render bound of this sprite for debugging? (default to false) - * @type {boolean} - */ - public renderDebug: bool = false; - - /** - * Color of the Sprite when no image is present. Format is a css color string. - * @type {string} - */ - public fillColor: string = 'rgb(255,255,255)'; - - /** - * Color of bound when render debug. (see renderDebug) Format is a css color string. - * @type {string} - */ - public renderDebugColor: string = 'rgba(0,255,0,0.5)'; - - /** - * Color of points when render debug. (see renderDebug) Format is a css color string. - * @type {string} - */ - public renderDebugPointColor: string = 'rgba(255,255,255,1)'; - - /** - * Renders the bounding box around this Sprite and the contact points. Useful for visually debugging. - * @param camera {Camera} Camera the bound will be rendered to. - * @param cameraOffsetX {number} X offset of bound to the camera. - * @param cameraOffsetY {number} Y offset of bound to the camera. - */ - /* - private renderBounds(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) { - - this._dx = cameraOffsetX + (this.frameBounds.topLeft.x - camera.worldView.x); - this._dy = cameraOffsetY + (this.frameBounds.topLeft.y - camera.worldView.y); - - this.context.fillStyle = this.renderDebugColor; - this.context.fillRect(this._dx, this._dy, this.frameBounds.width, this.frameBounds.height); - - //this.context.fillStyle = this.renderDebugPointColor; - - //var hw = this.frameBounds.halfWidth * this.scale.x; - //var hh = this.frameBounds.halfHeight * this.scale.y; - //var sw = (this.frameBounds.width * this.scale.x) - 1; - //var sh = (this.frameBounds.height * this.scale.y) - 1; - - //this.context.fillRect(this._dx, this._dy, 1, 1); // top left - //this.context.fillRect(this._dx + hw, this._dy, 1, 1); // top center - //this.context.fillRect(this._dx + sw, this._dy, 1, 1); // top right - //this.context.fillRect(this._dx, this._dy + hh, 1, 1); // left center - //this.context.fillRect(this._dx + hw, this._dy + hh, 1, 1); // center - //this.context.fillRect(this._dx + sw, this._dy + hh, 1, 1); // right center - //this.context.fillRect(this._dx, this._dy + sh, 1, 1); // bottom left - //this.context.fillRect(this._dx + hw, this._dy + sh, 1, 1); // bottom center - //this.context.fillRect(this._dx + sw, this._dy + sh, 1, 1); // bottom right - - } - */ - - - } - -} \ No newline at end of file diff --git a/Phaser/core/Group.ts b/Phaser/core/Group.ts index 414ea363..d06b3caa 100644 --- a/Phaser/core/Group.ts +++ b/Phaser/core/Group.ts @@ -1,7 +1,7 @@ /// /// -/// -/// +/// +/// /** * Phaser - Group @@ -29,8 +29,8 @@ module Phaser { this.ID = this.game.world.getNextGroupID(); - this.transform = new Phaser.Components.Transform(this); - this.texture = new Phaser.Components.Texture(this); + this.transform = new Phaser.Components.TransformManager(this); + this.texture = new Phaser.Display.Texture(this); this.texture.opaque = false; } @@ -98,12 +98,12 @@ module Phaser { /** * Optional texture used in the background of the Camera. */ - public texture: Phaser.Components.Texture; + public texture: Phaser.Display.Texture; /** * The transform component. */ - public transform: Phaser.Components.Transform; + public transform: Phaser.Components.TransformManager; /** * A boolean representing if the Group has been modified in any way via a scale, rotate, flip or skew. diff --git a/Phaser/core/Plugin.ts b/Phaser/core/Plugin.ts new file mode 100644 index 00000000..5b25f182 --- /dev/null +++ b/Phaser/core/Plugin.ts @@ -0,0 +1,117 @@ +/// + +/** +* Phaser - Plugin +*/ + +module Phaser { + + export class Plugin { + + constructor(game: Phaser.Game, parent) { + + this.game = game; + this.parent = parent; + + this.active = false; + this.visible = false; + + this.hasPreUpdate = false; + this.hasUpdate = false; + this.hasPostUpdate = false; + + this.hasPreRender = false; + this.hasRender = false; + this.hasPostRender = false; + + } + + /** + * Local reference to Game. + */ + public game: Game; + + /** + * The object that owns this Plugin (i.e. Camera, Game, Stage, etc). + */ + public parent; + + /** + * Controls whether preUpdate, update or postUpdate are called + */ + public active: bool; + + /** + * Controls whether preRender, render or postRender are called + */ + public visible: bool; + + /** + * Quick access booleans to avoid having to do a function existence check during tight inner loops + */ + public hasPreUpdate: bool; + public hasUpdate: bool; + public hasPostUpdate: bool; + + public hasPreRender: bool; + public hasRender: bool; + public hasPostRender: bool; + + /** + * Pre-update is called at the start of the update cycle, before any other updates have taken place. + * It is only called if active is set to true. + */ + public preUpdate() { + } + + /** + * Pre-update is called at the start of the update cycle, before any other updates have taken place. + * It is only called if active is set to true. + */ + public update() { + } + + /** + * Post-update is called at the end of the objects update cycle, after other update logic has taken place. + * It is only called if active is set to true. + */ + public postUpdate() { + } + + /** + * Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run. + * It is only called if visible is set to true. + */ + public preRender() { + } + + /** + * Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run. + * It is only called if visible is set to true. + */ + public render() { + } + + /** + * Post-render is called after every camera and game object has been rendered, also after any custom postRender callbacks have been run. + * It is only called if visible is set to true. + */ + public postRender() { + } + + /** + * Clear down this Plugin and null out references + */ + public destroy() { + + this.game = null; + this.parent = null; + + this.active = false; + this.visible = false; + + } + + } + +} diff --git a/Phaser/core/PluginManager.ts b/Phaser/core/PluginManager.ts new file mode 100644 index 00000000..3124cddd --- /dev/null +++ b/Phaser/core/PluginManager.ts @@ -0,0 +1,222 @@ +/// +/// + +/** +* Phaser - PluginManager +*/ + +module Phaser { + + export class PluginManager { + + constructor(game:Game, parent) { + + this.game = game; + + this._parent = parent; + + this.plugins = []; + + } + + /** + * Local reference to Game. + */ + public game: Game; + + /** + * The object that owns this PluginManager. + */ + private _parent; + + /** + * Plugin loop pointer + * @type {number} + */ + private _p: number; + + /** + * Plugins array counter + * @type {number} + */ + private _pluginsLength: number; + + /** + * An Array of Plugins + * @type {Array} + */ + public plugins: Phaser.Plugin[]; + + /** + * Add a new Plugin to the PluginManager. + * The plugins game and parent reference are set to this game and pluginmanager parent. + * @type {Phaser.Plugin} + */ + public add(plugin):any { + + var result: bool = false; + + // Prototype? + if (typeof plugin === 'function') + { + plugin = new plugin(this.game, this._parent); + } + else + { + plugin.game = this.game; + plugin.parent = this._parent; + } + + // Check for methods now to avoid having to do this every loop + + if (typeof plugin['preUpdate'] === 'function') + { + plugin.hasPreUpdate = true; + result = true; + } + + if (typeof plugin['update'] === 'function') + { + plugin.hasUpdate = true; + result = true; + } + + if (typeof plugin['postUpdate'] === 'function') + { + plugin.hasPostUpdate = true; + result = true; + } + + if (typeof plugin['preRender'] === 'function') + { + plugin.hasPreRender = true; + result = true; + } + + if (typeof plugin['render'] === 'function') + { + plugin.hasRender = true; + result = true; + } + + if (typeof plugin['postRender'] === 'function') + { + plugin.hasPostRender = true; + result = true; + } + + // The plugin must have at least one of the above functions to be added to the PluginManager. + if (result == true) + { + if (plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate) + { + plugin.active = true; + } + + if (plugin.hasPreRender || plugin.hasRender || plugin.hasPostRender) + { + plugin.visible = true; + } + + this._pluginsLength = this.plugins.push(plugin); + + return plugin; + } + else + { + return null; + } + + } + + public remove(plugin) { + + // TODO :) + this._pluginsLength--; + + } + + public preUpdate() { + + for (this._p = 0; this._p < this._pluginsLength; this._p++) + { + if (this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate) + { + this.plugins[this._p].preUpdate(); + } + } + + } + + public update() { + + for (this._p = 0; this._p < this._pluginsLength; this._p++) + { + if (this.plugins[this._p].active && this.plugins[this._p].hasUpdate) + { + this.plugins[this._p].update(); + } + } + + } + + public postUpdate() { + + for (this._p = 0; this._p < this._pluginsLength; this._p++) + { + if (this.plugins[this._p].active && this.plugins[this._p].hasPostUpdate) + { + this.plugins[this._p].postUpdate(); + } + } + + } + + public preRender() { + + for (this._p = 0; this._p < this._pluginsLength; this._p++) + { + if (this.plugins[this._p].visible && this.plugins[this._p].hasPreRender) + { + this.plugins[this._p].preRender(); + } + } + + } + + public render() { + + for (this._p = 0; this._p < this._pluginsLength; this._p++) + { + if (this.plugins[this._p].visible && this.plugins[this._p].hasRender) + { + this.plugins[this._p].render(); + } + } + + } + + public postRender() { + + for (this._p = 0; this._p < this._pluginsLength; this._p++) + { + if (this.plugins[this._p].visible && this.plugins[this._p].hasPostRender) + { + this.plugins[this._p].postRender(); + } + } + + } + + public destroy() { + + this.plugins.length = 0; + this._pluginsLength = 0; + this.game = null; + this._parent = null; + + } + + } + +} \ No newline at end of file diff --git a/Phaser/components/CSS3Filters.ts b/Phaser/display/CSS3Filters.ts similarity index 99% rename from Phaser/components/CSS3Filters.ts rename to Phaser/display/CSS3Filters.ts index 235d2ad7..75d3d5a6 100644 --- a/Phaser/components/CSS3Filters.ts +++ b/Phaser/display/CSS3Filters.ts @@ -1,12 +1,12 @@ /// /** -* Phaser - Components - CSS3Filters +* Phaser - Display - CSS3Filters * * Allows for easy addition and modification of CSS3 Filters on DOM objects (typically the Game.Stage.canvas). */ -module Phaser.Components { +module Phaser.Display { export class CSS3Filters { diff --git a/Phaser/gameobjects/DynamicTexture.ts b/Phaser/display/DynamicTexture.ts similarity index 98% rename from Phaser/gameobjects/DynamicTexture.ts rename to Phaser/display/DynamicTexture.ts index 3bd7c60a..accc0db6 100644 --- a/Phaser/gameobjects/DynamicTexture.ts +++ b/Phaser/display/DynamicTexture.ts @@ -1,10 +1,9 @@ /// /// /// -/// /** -* Phaser - DynamicTexture +* Phaser - Display - DynamicTexture * * A DynamicTexture can be thought of as a mini canvas into which you can draw anything. * Game Objects can be assigned a DynamicTexture, so when they render in the world they do so @@ -34,7 +33,7 @@ module Phaser { this.canvas.height = height; this.context = this.canvas.getContext('2d'); - this.css3 = new Phaser.Components.CSS3Filters(this.canvas); + this.css3 = new Phaser.Display.CSS3Filters(this.canvas); this.bounds = new Rectangle(0, 0, width, height); @@ -66,7 +65,7 @@ module Phaser { * Only really useful if you attach this canvas to the DOM. * @type {Phaser.Components.CSS3Filters} */ - public css3: Phaser.Components.CSS3Filters; + public css3: Phaser.Display.CSS3Filters; /** * Bound of this texture with width and height info. diff --git a/Phaser/components/Texture.ts b/Phaser/display/Texture.ts similarity index 98% rename from Phaser/components/Texture.ts rename to Phaser/display/Texture.ts index 661f9a21..769fa48f 100644 --- a/Phaser/components/Texture.ts +++ b/Phaser/display/Texture.ts @@ -1,14 +1,14 @@ /// -/// /// +/// /** -* Phaser - Components - Texture +* Phaser - Display - Texture * * The Texture being used to render the object (Sprite, Group background, etc). Either Image based on a DynamicTexture. */ -module Phaser.Components { +module Phaser.Display { export class Texture { diff --git a/Phaser/components/sprite/Events.ts b/Phaser/gameobjects/Events.ts similarity index 97% rename from Phaser/components/sprite/Events.ts rename to Phaser/gameobjects/Events.ts index 7a66c3ef..bcf5feac 100644 --- a/Phaser/components/sprite/Events.ts +++ b/Phaser/gameobjects/Events.ts @@ -1,4 +1,4 @@ -/// +/// /** * Phaser - Components - Events @@ -6,7 +6,7 @@ * Signals that are dispatched by the Sprite and its various components */ -module Phaser.Components.Sprite { +module Phaser.Components { export class Events { diff --git a/Phaser/gameobjects/GameObjectFactory.ts b/Phaser/gameobjects/GameObjectFactory.ts index 294bf2a1..0a8bef3b 100644 --- a/Phaser/gameobjects/GameObjectFactory.ts +++ b/Phaser/gameobjects/GameObjectFactory.ts @@ -1,12 +1,12 @@ /// /// -/// -/// +/// +/// /// -/// +/// /// -/// -/// +/// +/// /** * Phaser - GameObjectFactory @@ -76,8 +76,8 @@ module Phaser { * @param [downFrame] {string|number} This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. * @returns {Button} The newly created button object. */ - public button(x?: number = 0, y?: number = 0, key?: string = null, callback? = null, callbackContext? = null, overFrame? = null, outFrame? = null, downFrame? = null): Button { - return