Fixed Group creation arguments

This commit is contained in:
Richard Davey 2018-08-01 18:01:36 +01:00
parent 46552c8f2e
commit d50b72dd14
3 changed files with 63 additions and 28 deletions

View file

@ -126,9 +126,11 @@ var Group = new Class({
// Or they can pass in a child, or array of children AND a config object
if (config !== undefined)
if (config)
{
if (!Array.isArray(children))
// config has been set, are the children an array?
if (children && !Array.isArray(children))
{
children = [ children ];
}
@ -349,18 +351,16 @@ var Group = new Class({
config = [ config ];
}
if (config[0].key === undefined)
{
return [];
}
var output = [];
for (var i = 0; i < config.length; i++)
if (config[0].key)
{
var entries = this.createFromConfig(config[i]);
output = output.concat(entries);
for (var i = 0; i < config.length; i++)
{
var entries = this.createFromConfig(config[i]);
output = output.concat(entries);
}
}
return output;

View file

@ -9,6 +9,7 @@ var Class = require('../../utils/Class');
var CONST = require('./const');
var GetFastValue = require('../../utils/object/GetFastValue');
var Group = require('../../gameobjects/group/Group');
var IsPlainObject = require('../../utils/object/IsPlainObject');
/**
* @typedef {object} PhysicsGroupConfig
@ -88,14 +89,33 @@ var PhysicsGroup = new Class({
function PhysicsGroup (world, scene, children, config)
{
if (config === undefined && !Array.isArray(children) && typeof children === 'object')
if (!children && !config)
{
config = {
createCallback: this.createCallbackHandler,
removeCallback: this.removeCallbackHandler
};
}
else if (IsPlainObject(children))
{
// children is a plain object, so swizzle them:
config = children;
children = null;
config.createCallback = this.createCallbackHandler;
config.removeCallback = this.removeCallbackHandler;
}
else if (config === undefined)
else if (Array.isArray(children) && IsPlainObject(children[0]))
{
config = {};
// children is an array of plain objects
config = children;
children = null;
config.forEach(function (singleConfig)
{
singleConfig.createCallback = this.createCallbackHandler;
singleConfig.removeCallback = this.removeCallbackHandler;
});
}
/**
@ -107,9 +127,6 @@ var PhysicsGroup = new Class({
*/
this.world = world;
config.createCallback = this.createCallbackHandler;
config.removeCallback = this.removeCallbackHandler;
/**
* The class to create new group members from.
*

View file

@ -4,12 +4,11 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
// Phaser.Physics.Arcade.StaticGroup
var ArcadeSprite = require('./ArcadeSprite');
var Class = require('../../utils/Class');
var CONST = require('./const');
var Group = require('../../gameobjects/group/Group');
var IsPlainObject = require('../../utils/object/IsPlainObject');
/**
* @classdesc
@ -34,14 +33,39 @@ var StaticPhysicsGroup = new Class({
function StaticPhysicsGroup (world, scene, children, config)
{
if (config === undefined && !Array.isArray(children) && typeof children === 'object')
if (!children && !config)
{
config = {
createCallback: this.createCallbackHandler,
removeCallback: this.removeCallbackHandler,
createMultipleCallback: this.createMultipleCallbackHandler,
classType: ArcadeSprite
};
}
else if (IsPlainObject(children))
{
// children is a plain object, so swizzle them:
config = children;
children = null;
config.createCallback = this.createCallbackHandler;
config.removeCallback = this.removeCallbackHandler;
config.createMultipleCallback = this.createMultipleCallbackHandler;
config.classType = ArcadeSprite;
}
else if (config === undefined)
else if (Array.isArray(children) && IsPlainObject(children[0]))
{
config = {};
// children is an array of plain objects
config = children;
children = null;
config.forEach(function (singleConfig)
{
singleConfig.createCallback = this.createCallbackHandler;
singleConfig.removeCallback = this.removeCallbackHandler;
singleConfig.createMultipleCallback = this.createMultipleCallbackHandler;
singleConfig.classType = ArcadeSprite;
});
}
/**
@ -53,12 +77,6 @@ var StaticPhysicsGroup = new Class({
*/
this.world = world;
config.createCallback = this.createCallbackHandler;
config.removeCallback = this.removeCallbackHandler;
config.createMultipleCallback = this.createMultipleCallbackHandler;
config.classType = ArcadeSprite;
/**
* [description]
*