From 84ba1ba191854b6b5ed067ce08ddf590357c754f Mon Sep 17 00:00:00 2001 From: samme Date: Sat, 28 Apr 2018 08:41:32 -0700 Subject: [PATCH 1/3] Correct `source` checks in setEmitZone --- src/gameobjects/particles/ParticleEmitter.js | 25 ++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/gameobjects/particles/ParticleEmitter.js b/src/gameobjects/particles/ParticleEmitter.js index d2c1635e8..bcd3c31d0 100644 --- a/src/gameobjects/particles/ParticleEmitter.js +++ b/src/gameobjects/particles/ParticleEmitter.js @@ -1571,29 +1571,30 @@ var ParticleEmitter = new Class({ var type = GetFastValue(zoneConfig, 'type', 'random'); var source = GetFastValue(zoneConfig, 'source', null); - // TODO: - // For an EdgeZone, only source.getPoints(quantity, stepRate) is required. - // For a RandomZone, only source.getRandomPoint(point) is required. - // Any object implementing getPoint(position) could also be assigned here (instead of new EdgeZone, new RandomZone). - - if (source && typeof source.getPoint === 'function') + if (source) { switch (type) { case 'random': - this.emitZone = new RandomZone(source); + if (typeof source.getRandomPoint === 'function') + { + this.emitZone = new RandomZone(source); + } break; case 'edge': - var quantity = GetFastValue(zoneConfig, 'quantity', 1); - var stepRate = GetFastValue(zoneConfig, 'stepRate', 0); - var yoyo = GetFastValue(zoneConfig, 'yoyo', false); - var seamless = GetFastValue(zoneConfig, 'seamless', true); + if (typeof source.getPoints === 'function') + { + var quantity = GetFastValue(zoneConfig, 'quantity', 1); + var stepRate = GetFastValue(zoneConfig, 'stepRate', 0); + var yoyo = GetFastValue(zoneConfig, 'yoyo', false); + var seamless = GetFastValue(zoneConfig, 'seamless', true); - this.emitZone = new EdgeZone(source, quantity, stepRate, yoyo, seamless); + this.emitZone = new EdgeZone(source, quantity, stepRate, yoyo, seamless); + } break; } From f59f90d2ca0e73be18b8ddf189af2124544a8c8b Mon Sep 17 00:00:00 2001 From: samme Date: Sat, 28 Apr 2018 13:09:59 -0700 Subject: [PATCH 2/3] Correct `source` types in *ZoneConfig definitions --- src/gameobjects/particles/ParticleEmitter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gameobjects/particles/ParticleEmitter.js b/src/gameobjects/particles/ParticleEmitter.js index bcd3c31d0..931195c08 100644 --- a/src/gameobjects/particles/ParticleEmitter.js +++ b/src/gameobjects/particles/ParticleEmitter.js @@ -66,7 +66,7 @@ var Wrap = require('../../math/Wrap'); /** * @typedef {object} ParticleEmitterEdgeZoneConfig * - * @property {EdgeZoneSource|RandomZoneSource} source - A shape representing the zone. See {@link Phaser.GameObjects.Particles.Zones.EdgeZone#source}. + * @property {EdgeZoneSource} source - A shape representing the zone. See {@link Phaser.GameObjects.Particles.Zones.EdgeZone#source}. * @property {string} type - 'edge'. * @property {integer} quantity - The number of particles to place on the source edge. Set to 0 to use `stepRate` instead. * @property {float} [stepRate] - The distance between each particle. When set, `quantity` is implied and should be set to 0. @@ -77,7 +77,7 @@ var Wrap = require('../../math/Wrap'); /** * @typedef {object} ParticleEmitterRandomZoneConfig * - * @property {EdgeZoneSource|RandomZoneSource} source - A shape representing the zone. See {@link Phaser.GameObjects.Particles.Zones.RandomZone#source}. + * @property {RandomZoneSource} source - A shape representing the zone. See {@link Phaser.GameObjects.Particles.Zones.RandomZone#source}. * @property {string} [type] - 'random'. */ From 5fc6f94c673d648b6e161a6a1e7d4c469992eb15 Mon Sep 17 00:00:00 2001 From: samme Date: Sat, 28 Apr 2018 09:07:07 -0700 Subject: [PATCH 3/3] Remove `source` checks in setEmitZone --- src/gameobjects/particles/ParticleEmitter.js | 31 +++++++------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/gameobjects/particles/ParticleEmitter.js b/src/gameobjects/particles/ParticleEmitter.js index 931195c08..d0b13c24d 100644 --- a/src/gameobjects/particles/ParticleEmitter.js +++ b/src/gameobjects/particles/ParticleEmitter.js @@ -1571,33 +1571,24 @@ var ParticleEmitter = new Class({ var type = GetFastValue(zoneConfig, 'type', 'random'); var source = GetFastValue(zoneConfig, 'source', null); - if (source) + switch (type) { - switch (type) - { - case 'random': + case 'random': - if (typeof source.getRandomPoint === 'function') - { - this.emitZone = new RandomZone(source); - } + this.emitZone = new RandomZone(source); - break; + break; - case 'edge': + case 'edge': - if (typeof source.getPoints === 'function') - { - var quantity = GetFastValue(zoneConfig, 'quantity', 1); - var stepRate = GetFastValue(zoneConfig, 'stepRate', 0); - var yoyo = GetFastValue(zoneConfig, 'yoyo', false); - var seamless = GetFastValue(zoneConfig, 'seamless', true); + var quantity = GetFastValue(zoneConfig, 'quantity', 1); + var stepRate = GetFastValue(zoneConfig, 'stepRate', 0); + var yoyo = GetFastValue(zoneConfig, 'yoyo', false); + var seamless = GetFastValue(zoneConfig, 'seamless', true); - this.emitZone = new EdgeZone(source, quantity, stepRate, yoyo, seamless); - } + this.emitZone = new EdgeZone(source, quantity, stepRate, yoyo, seamless); - break; - } + break; } }