From af9924d441cb53fe0f9a4eb45c723a1a78bbec6e Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 12 Dec 2019 19:27:50 -0600 Subject: [PATCH] refactor: more powerful emission --- packages/physics/traits/emitter.trait.js | 35 +++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/physics/traits/emitter.trait.js b/packages/physics/traits/emitter.trait.js index 030b783..de1d9dd 100644 --- a/packages/physics/traits/emitter.trait.js +++ b/packages/physics/traits/emitter.trait.js @@ -83,6 +83,12 @@ export class Emitter extends decorate(Trait) { return hooks; } + emitParticleJson(json) { + return Entity.loadOrInstance(json).then((particle) => { + this.entity.emitParticleEntity(particle); + }); + } + listeners() { return { @@ -151,30 +157,18 @@ export class Emitter extends decorate(Trait) { }, emitParticleJson: (json) => { - return Entity.loadOrInstance(json).then((particle) => { - this.entity.emitParticleEntity(particle); - return particle; - }); - }, - - emitParticle: (key, order = {}) => { - const particleJson = this.particles[key] - if (!particleJson) { - return; - } - const mergedJson = merge({}, particleJson, order); let { count = 1, rate = 0, - } = mergedJson; + } = json; if (0 === rate) { for (let i = 0; i < count; ++i) { - this.entity.emitParticleJson(mergedJson); + this.emitParticleJson(json); } } else { const ticker = new Ticker(rate); - this.entity.emitParticleJson(mergedJson); + this.emitParticleJson(json); count -= 1; if (count > 0) { const removeEmission = () => { @@ -185,7 +179,7 @@ export class Emitter extends decorate(Trait) { }; this.entity.on('destroy', removeEmission); ticker.on('tick', () => { - this.entity.emitParticleJson(mergedJson); + this.emitParticleJson(json); if (0 >= --count) { removeEmission(); } @@ -195,6 +189,15 @@ export class Emitter extends decorate(Trait) { } }, + emitParticle: (key, json = {}) => { + const particleJson = this.particles[key] + if (!particleJson) { + return; + } + const mergedJson = merge({}, particleJson, json); + this.entity.emitParticleJson(mergedJson); + }, + }; }