From 8ec9061b43e32cd0044c7db9127ab59bf5fd3c25 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 4 Apr 2017 23:58:33 +0100 Subject: [PATCH] Removed 'group' / 'parent' argument and forced to the State children component. You should use 'make' if you wish to add elsewhere. --- v3/src/gameobjects/FactoryContainer.js | 8 -------- .../bitmaptext/dynamic/DynamicBitmapTextFactory.js | 2 +- .../bitmaptext/static/BitmapTextFactory.js | 2 +- v3/src/gameobjects/blitter/BlitterFactory.js | 6 ++---- v3/src/gameobjects/graphics/GraphicsFactory.js | 2 +- v3/src/gameobjects/image/ImageFactory.js | 6 ++---- v3/src/gameobjects/sprite/SpriteFactory.js | 11 ++--------- v3/src/gameobjects/text/static/TextFactory.js | 2 +- v3/src/state/systems/GameObjectCreator.js | 2 ++ v3/src/state/systems/GameObjectFactory.js | 4 +++- 10 files changed, 15 insertions(+), 30 deletions(-) diff --git a/v3/src/gameobjects/FactoryContainer.js b/v3/src/gameobjects/FactoryContainer.js index b40ebf72c..eb50696be 100644 --- a/v3/src/gameobjects/FactoryContainer.js +++ b/v3/src/gameobjects/FactoryContainer.js @@ -12,20 +12,14 @@ var factories = {}; var FactoryContainer = function () { - // console.log('FactoryContainer is alive'); - this.register = function (factory) { if (factories.hasOwnProperty(factory.KEY)) { - // console.log('Already registered', factory.KEY); - return this.getType(factory.KEY); } else { - // console.log('registering', factory.KEY); - factories[factory.KEY] = { add: factory.add, make: factory.make @@ -46,8 +40,6 @@ var FactoryContainer = function () { if (factories.hasOwnProperty(factory)) { - // console.log('Loading', factory); - dest[factory] = (isFactory) ? factories[factory].add : factories[factory].make; } } diff --git a/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js b/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js index 8753ad627..285833263 100644 --- a/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js +++ b/v3/src/gameobjects/bitmaptext/dynamic/DynamicBitmapTextFactory.js @@ -7,7 +7,7 @@ var DynamicBitmapTextFactory = { add: function (x, y, font, text, size, align) { - return this.state.children.add(new BitmapText(this.state, x, y, font, text, size, align)); + return this.children.add(new BitmapText(this.state, x, y, font, text, size, align)); }, make: function (x, y, font, text, size, align) diff --git a/v3/src/gameobjects/bitmaptext/static/BitmapTextFactory.js b/v3/src/gameobjects/bitmaptext/static/BitmapTextFactory.js index fc164ab7b..0a0c6b898 100644 --- a/v3/src/gameobjects/bitmaptext/static/BitmapTextFactory.js +++ b/v3/src/gameobjects/bitmaptext/static/BitmapTextFactory.js @@ -7,7 +7,7 @@ var BitmapTextFactory = { add: function (x, y, font, text, size, align) { - return this.state.children.add(new BitmapText(this.state, x, y, font, text, size, align)); + return this.children.add(new BitmapText(this.state, x, y, font, text, size, align)); }, make: function (x, y, font, text, size, align) diff --git a/v3/src/gameobjects/blitter/BlitterFactory.js b/v3/src/gameobjects/blitter/BlitterFactory.js index 61813a09c..3bcc4ef5c 100644 --- a/v3/src/gameobjects/blitter/BlitterFactory.js +++ b/v3/src/gameobjects/blitter/BlitterFactory.js @@ -6,11 +6,9 @@ var BlitterFactory = { KEY: 'blitter', - add: function (x, y, key, frame, parent) + add: function (x, y, key, frame) { - if (parent === undefined) { parent = this.state; } - - return parent.children.add(new Blitter(this.state, x, y, key, frame)); + return this.children.add(new Blitter(this.state, x, y, key, frame)); }, make: function (x, y, key, frame) diff --git a/v3/src/gameobjects/graphics/GraphicsFactory.js b/v3/src/gameobjects/graphics/GraphicsFactory.js index d6346e8ae..be666f1a5 100644 --- a/v3/src/gameobjects/graphics/GraphicsFactory.js +++ b/v3/src/gameobjects/graphics/GraphicsFactory.js @@ -7,7 +7,7 @@ var GraphicsFactory = { add: function (options) { - return this.state.children.add(new Graphics(this.state, options)); + return this.children.add(new Graphics(this.state, options)); }, make: function (options) diff --git a/v3/src/gameobjects/image/ImageFactory.js b/v3/src/gameobjects/image/ImageFactory.js index 8ee9bdbcf..90ee83199 100644 --- a/v3/src/gameobjects/image/ImageFactory.js +++ b/v3/src/gameobjects/image/ImageFactory.js @@ -22,11 +22,9 @@ var ImageFactory = { * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. * @return {Phaser.Image} The newly created Image object. */ - add: function (x, y, key, frame, parent) + add: function (x, y, key, frame) { - if (parent === undefined) { parent = this.state; } - - return parent.children.add(new Image(this.state, x, y, key, frame)); + return this.children.add(new Image(this.state, x, y, key, frame)); }, make: function (x, y, key, frame) diff --git a/v3/src/gameobjects/sprite/SpriteFactory.js b/v3/src/gameobjects/sprite/SpriteFactory.js index 27e420091..b30cf6b5d 100644 --- a/v3/src/gameobjects/sprite/SpriteFactory.js +++ b/v3/src/gameobjects/sprite/SpriteFactory.js @@ -26,20 +26,13 @@ var SpriteFactory = { * @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group. * @return {Phaser.Sprite} The newly created Sprite object. */ - add: function (x, y, key, frame, group) + add: function (x, y, key, frame) { - if (group === undefined) { group = this.state; } - - // console.log('ImageFactory.add', key, x, y, frame, group); - // console.log('into State', this.state); - - return group.children.add(new Sprite(this.state, x, y, key, frame)); + return this.children.add(new Sprite(this.state, x, y, key, frame)); }, make: function (x, y, key, frame) { - // console.log('ImageFactory.make', key, x, y, frame); - return new Sprite(this.state, x, y, key, frame); } diff --git a/v3/src/gameobjects/text/static/TextFactory.js b/v3/src/gameobjects/text/static/TextFactory.js index abdc2d417..baa0a0099 100644 --- a/v3/src/gameobjects/text/static/TextFactory.js +++ b/v3/src/gameobjects/text/static/TextFactory.js @@ -7,7 +7,7 @@ var TextFactory = { add: function (x, y, text, style) { - return this.state.children.add(new Text(this.state, x, y, text, style)); + return this.children.add(new Text(this.state, x, y, text, style)); }, make: function (x, y, text, style) diff --git a/v3/src/state/systems/GameObjectCreator.js b/v3/src/state/systems/GameObjectCreator.js index 4c63b13f1..78275075f 100644 --- a/v3/src/state/systems/GameObjectCreator.js +++ b/v3/src/state/systems/GameObjectCreator.js @@ -17,6 +17,8 @@ var GameObjectCreator = function (state) { this.state = state; + this.children = state.sys.children; + FactoryContainer.load(this, false); }; diff --git a/v3/src/state/systems/GameObjectFactory.js b/v3/src/state/systems/GameObjectFactory.js index 4749290d1..9a249a8da 100644 --- a/v3/src/state/systems/GameObjectFactory.js +++ b/v3/src/state/systems/GameObjectFactory.js @@ -17,6 +17,8 @@ var GameObjectFactory = function (state) { this.state = state; + this.children = state.sys.children; + FactoryContainer.load(this, true); }; @@ -26,7 +28,7 @@ GameObjectFactory.prototype = { existing: function (child) { - return this.state.children.add(child); + return this.children.add(child); }, destroy: function ()