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

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.
@@ -4,13 +4,13 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./InfectionStage"], factory);
7
+ define(["require", "exports", "./InfectionStage.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Infection = void 0;
13
- const InfectionStage_1 = require("./InfectionStage");
13
+ const InfectionStage_js_1 = require("./InfectionStage.js");
14
14
  class Infection {
15
15
  constructor() {
16
16
  this.cure = false;
@@ -39,7 +39,7 @@
39
39
  return;
40
40
  }
41
41
  this.stages = data.stages.map((t) => {
42
- const s = new InfectionStage_1.InfectionStage();
42
+ const s = new InfectionStage_js_1.InfectionStage();
43
43
  s.load(t);
44
44
  return s;
45
45
  });
@@ -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
@@ -18,43 +18,42 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
18
  if (v !== undefined) module.exports = v;
19
19
  }
20
20
  else if (typeof define === "function" && define.amd) {
21
- define(["require", "exports", "./Options/Classes/Infection", "./InfectionInstance", "./ParticlesInfecter", "./Options/Interfaces/IInfection", "./Options/Interfaces/IInfectionStage"], factory);
21
+ define(["require", "exports", "./Options/Classes/Infection.js", "./InfectionInstance.js", "./ParticlesInfecter.js", "./Options/Interfaces/IInfection.js", "./Options/Interfaces/IInfectionStage.js"], factory);
22
22
  }
23
23
  })(function (require, exports) {
24
24
  "use strict";
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.loadInfectionPlugin = void 0;
27
- const Infection_1 = require("./Options/Classes/Infection");
28
- const InfectionInstance_1 = require("./InfectionInstance");
29
- const ParticlesInfecter_1 = require("./ParticlesInfecter");
27
+ const Infection_js_1 = require("./Options/Classes/Infection.js");
28
+ const InfectionInstance_js_1 = require("./InfectionInstance.js");
29
+ const ParticlesInfecter_js_1 = require("./ParticlesInfecter.js");
30
30
  class InfectionPlugin {
31
31
  constructor() {
32
32
  this.id = "infection";
33
33
  }
34
34
  getPlugin(container) {
35
- return new InfectionInstance_1.InfectionInstance(container);
35
+ return new InfectionInstance_js_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) {
43
- options.infection = infectionOptions = new Infection_1.Infection();
42
+ if (infectionOptions?.load === undefined) {
43
+ options.infection = infectionOptions = new Infection_js_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_js_1.ParticlesInfecter(container), refresh);
56
55
  }
57
56
  exports.loadInfectionPlugin = loadInfectionPlugin;
58
- __exportStar(require("./Options/Interfaces/IInfection"), exports);
59
- __exportStar(require("./Options/Interfaces/IInfectionStage"), exports);
57
+ __exportStar(require("./Options/Interfaces/IInfection.js"), exports);
58
+ __exportStar(require("./Options/Interfaces/IInfectionStage.js"), exports);
60
59
  });