import { Particle } from '@pixi/particle-emitter'; function intValueSimple( this: PIXI.particles.PropertyList, lerp: number ): number { if (this.ease) lerp = this.ease(lerp); return (this.first.next.value - this.first.value) * lerp + this.first.value; } function intColorSimple( this: PIXI.particles.PropertyList, lerp: number ): number { if (this.ease) lerp = this.ease(lerp); const curVal = this.first.value; const nextVal = this.first.next.value; const r = (nextVal.r - curVal.r) * lerp + curVal.r; const g = (nextVal.g - curVal.g) * lerp + curVal.g; const b = (nextVal.b - curVal.b) * lerp + curVal.b; return PIXI.particles.ParticleUtils.combineRGBComponents(r, g, b); } function intValueComplex( this: PIXI.particles.PropertyList, lerp: number ): number { if (this.ease) lerp = this.ease(lerp); // make sure we are on the right segment let current = this.first; let next = current.next; if (!next) { return 0; } while (lerp > next.time) { current = next; next = next.next; } // convert the lerp value to the segment range lerp = (lerp - current.time) / (next.time - current.time); return (next.value - current.value) * lerp + current.value; } function intColorComplex( this: PIXI.particles.PropertyList, lerp: number ): number { if (this.ease) lerp = this.ease(lerp); // make sure we are on the right segment let current = this.first; let next = current.next; if (!next) { return 0; } while (lerp > next.time) { current = next; next = next.next; } // convert the lerp value to the segment range lerp = (lerp - current.time) / (next.time - current.time); const curVal = current.value; const nextVal = next.value; const r = (nextVal.r - curVal.r) * lerp + curVal.r; const g = (nextVal.g - curVal.g) * lerp + curVal.g; const b = (nextVal.b - curVal.b) * lerp + curVal.b; return PIXI.particles.ParticleUtils.combineRGBComponents(r, g, b); } function intValueStepped( this: PIXI.particles.PropertyList, lerp: number ): number { if (this.ease) lerp = this.ease(lerp); // make sure we are on the right segment let current = this.first; if (!current) { return 0; } while (current.next && lerp > current.next.time) { current = current.next; } return current.value; } function intColorStepped( this: PIXI.particles.PropertyList, lerp: number ): number { if (this.ease) lerp = this.ease(lerp); // make sure we are on the right segment let current = this.first; if (!current) { return 0; } while (current.next && lerp > current.next.time) { current = current.next; } const curVal = current.value; return PIXI.particles.ParticleUtils.combineRGBComponents( curVal.r, curVal.g, curVal.b ); } export const fixPIXIParticlesBug = () => { if (!PIXI.particles) { return; } PIXI.particles.PropertyList.prototype.reset = function (first: any): void { this.first = first; const isSimple = first.next && first.next.time >= 1; if (isSimple) { // @ts-ignore this.interpolate = this.isColor ? intColorSimple : intValueSimple; } else if (first.isStepped) { // @ts-ignore this.interpolate = this.isColor ? intColorStepped : intValueStepped; } else { // @ts-ignore this.interpolate = this.isColor ? intColorComplex : intValueComplex; } this.ease = this.first.ease; }; class PathBehavior extends PIXI.particles.behaviors.PathBehavior { agePercent: number; updateParticle(particle: Particle, deltaSec: number): void { // @ts-ignore this.agePercent = particle.agePercent; super.updateParticle(particle, deltaSec); } } PIXI.particles.Emitter.registerBehavior(PathBehavior); };