refactor: more powerful emission

This commit is contained in:
cha0s 2019-12-12 19:27:50 -06:00
parent 13cff8d3fc
commit af9924d441

View File

@ -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);
},
};
}