@tsparticles/plugin-infection 3.0.0-alpha.1 → 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,46 +20,43 @@
20
20
  init() {
21
21
  }
22
22
  async interact(p1, delta) {
23
- var _a, _b, _c, _d, _e;
24
23
  const infecter = this.container.infecter;
25
24
  if (!infecter) {
26
25
  return;
27
26
  }
28
27
  infecter.updateInfection(p1, delta.value);
29
- if (((_a = p1.infection) === null || _a === void 0 ? void 0 : _a.stage) === undefined) {
28
+ if (p1.infection?.stage === undefined) {
30
29
  return;
31
30
  }
32
31
  const container = this.container, options = container.actualOptions, infectionOptions = options.infection;
33
- if (!(infectionOptions === null || infectionOptions === void 0 ? void 0 : infectionOptions.enable) || infectionOptions.stages.length < 1) {
32
+ if (!infectionOptions?.enable || infectionOptions.stages.length < 1) {
34
33
  return;
35
34
  }
36
- const infectionStage1 = infectionOptions.stages[p1.infection.stage], pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * 2 + infectionStage1.radius * pxRatio, pos = p1.getPosition(), infectedStage1 = (_b = infectionStage1.infectedStage) !== null && _b !== void 0 ? _b : p1.infection.stage, query = container.particles.quadTree.queryCircle(pos, radius), infections = infectionStage1.rate, neighbors = query.length;
35
+ const infectionStage1 = infectionOptions.stages[p1.infection.stage], pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * 2 + infectionStage1.radius * pxRatio, pos = p1.getPosition(), infectedStage1 = infectionStage1.infectedStage ?? p1.infection.stage, query = container.particles.quadTree.queryCircle(pos, radius), infections = infectionStage1.rate, neighbors = query.length;
37
36
  for (const p2 of query) {
38
37
  const infP2 = p2;
39
38
  if (infP2 === p1 ||
40
39
  infP2.destroyed ||
41
40
  infP2.spawning ||
42
- !(((_c = infP2.infection) === null || _c === void 0 ? void 0 : _c.stage) === undefined || infP2.infection.stage !== p1.infection.stage)) {
41
+ !(infP2.infection?.stage === undefined || infP2.infection.stage !== p1.infection.stage) ||
42
+ (0, engine_1.getRandom)() >= infections / neighbors) {
43
43
  continue;
44
44
  }
45
- if ((0, engine_1.getRandom)() < infections / neighbors) {
46
- if (((_d = infP2.infection) === null || _d === void 0 ? void 0 : _d.stage) === undefined) {
47
- infecter.startInfection(infP2, infectedStage1);
48
- }
49
- else if (infP2.infection.stage < p1.infection.stage) {
50
- infecter.updateInfectionStage(infP2, infectedStage1);
51
- }
52
- else if (infP2.infection.stage > p1.infection.stage) {
53
- const infectionStage2 = infectionOptions.stages[infP2.infection.stage];
54
- const infectedStage2 = (_e = infectionStage2 === null || infectionStage2 === void 0 ? void 0 : infectionStage2.infectedStage) !== null && _e !== void 0 ? _e : infP2.infection.stage;
55
- infecter.updateInfectionStage(p1, infectedStage2);
56
- }
45
+ if (infP2.infection?.stage === undefined) {
46
+ infecter.startInfection(infP2, infectedStage1);
47
+ }
48
+ else if (infP2.infection.stage < p1.infection.stage) {
49
+ infecter.updateInfectionStage(infP2, infectedStage1);
50
+ }
51
+ else if (infP2.infection.stage > p1.infection.stage) {
52
+ const infectionStage2 = infectionOptions.stages[infP2.infection.stage];
53
+ const infectedStage2 = infectionStage2?.infectedStage ?? infP2.infection.stage;
54
+ infecter.updateInfectionStage(p1, infectedStage2);
57
55
  }
58
56
  }
59
57
  }
60
58
  isEnabled() {
61
- var _a, _b, _c;
62
- return (_c = (_b = (_a = this.container.actualOptions) === null || _a === void 0 ? void 0 : _a.infection) === null || _b === void 0 ? void 0 : _b.enable) !== null && _c !== void 0 ? _c : false;
59
+ return this.container.actualOptions?.infection?.enable ?? false;
63
60
  }
64
61
  reset() {
65
62
  }
package/umd/index.js CHANGED
@@ -35,24 +35,23 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
35
  return new InfectionInstance_1.InfectionInstance(container);
36
36
  }
37
37
  loadOptions(options, source) {
38
- if (!this.needsPlugin(source)) {
38
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
39
39
  return;
40
40
  }
41
41
  let infectionOptions = options.infection;
42
- if ((infectionOptions === null || infectionOptions === void 0 ? void 0 : infectionOptions.load) === undefined) {
42
+ if (infectionOptions?.load === undefined) {
43
43
  options.infection = infectionOptions = new Infection_1.Infection();
44
44
  }
45
- infectionOptions.load(source === null || source === void 0 ? void 0 : source.infection);
45
+ infectionOptions.load(source?.infection);
46
46
  }
47
47
  needsPlugin(options) {
48
- var _a, _b;
49
- return (_b = (_a = options === null || options === void 0 ? void 0 : options.infection) === null || _a === void 0 ? void 0 : _a.enable) !== null && _b !== void 0 ? _b : false;
48
+ return options?.infection?.enable ?? false;
50
49
  }
51
50
  }
52
- async function loadInfectionPlugin(engine) {
51
+ async function loadInfectionPlugin(engine, refresh = true) {
53
52
  const plugin = new InfectionPlugin();
54
- await engine.addPlugin(plugin);
55
- await engine.addInteractor("particlesInfection", (container) => new ParticlesInfecter_1.ParticlesInfecter(container));
53
+ await engine.addPlugin(plugin, refresh);
54
+ await engine.addInteractor("particlesInfection", (container) => new ParticlesInfecter_1.ParticlesInfecter(container), refresh);
56
55
  }
57
56
  exports.loadInfectionPlugin = loadInfectionPlugin;
58
57
  __exportStar(require("./Options/Interfaces/IInfection"), exports);