@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.
- package/README.md +16 -12
- package/browser/Infecter.js +54 -56
- package/browser/InfectionInstance.js +7 -8
- package/browser/Options/Classes/Infection.js +1 -1
- package/browser/ParticlesInfecter.js +16 -19
- package/browser/index.js +12 -13
- package/browser/package.json +1 -0
- package/cjs/Infecter.js +54 -56
- package/cjs/InfectionInstance.js +7 -8
- package/cjs/Options/Classes/Infection.js +2 -2
- package/cjs/ParticlesInfecter.js +32 -46
- package/cjs/index.js +15 -27
- package/cjs/package.json +1 -0
- package/esm/Infecter.js +54 -56
- package/esm/InfectionInstance.js +7 -8
- package/esm/Options/Classes/Infection.js +1 -1
- package/esm/ParticlesInfecter.js +16 -19
- package/esm/index.js +12 -13
- package/esm/package.json +1 -0
- package/package.json +23 -6
- package/report.html +4 -4
- package/tsparticles.plugin.infection.js +93 -87
- package/tsparticles.plugin.infection.min.js +1 -1
- package/tsparticles.plugin.infection.min.js.LICENSE.txt +1 -8
- package/types/Infecter.d.ts +3 -3
- package/types/InfectionInstance.d.ts +3 -3
- package/types/Options/Classes/Infection.d.ts +2 -2
- package/types/Options/Classes/InfectionStage.d.ts +2 -3
- package/types/Options/Interfaces/IInfection.d.ts +1 -1
- package/types/ParticlesInfecter.d.ts +2 -3
- package/types/Types.d.ts +3 -3
- package/types/index.d.ts +3 -3
- package/umd/Infecter.js +54 -56
- package/umd/InfectionInstance.js +8 -9
- package/umd/Options/Classes/Infection.js +3 -3
- package/umd/ParticlesInfecter.js +16 -19
- package/umd/index.js +15 -16
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# tsParticles Infection Plugin
|
|
4
4
|
|
|
5
|
-
[](https://www.jsdelivr.com/package/npm/@tsparticles/plugin-infection)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/plugin-infection)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/plugin-infection) [](https://github.com/sponsors/matteobruni)
|
|
8
8
|
|
|
9
9
|
[tsParticles](https://github.com/matteobruni/tsparticles) plugin for particles infection simulation effect.
|
|
10
10
|
|
|
@@ -26,7 +26,7 @@ Once the scripts are loaded you can set up `tsParticles` and the plugin like thi
|
|
|
26
26
|
|
|
27
27
|
```javascript
|
|
28
28
|
(async () => {
|
|
29
|
-
await loadInfectionPlugin();
|
|
29
|
+
await loadInfectionPlugin(tsParticles);
|
|
30
30
|
|
|
31
31
|
await tsParticles.load({
|
|
32
32
|
id: "tsparticles",
|
|
@@ -42,29 +42,33 @@ Once the scripts are loaded you can set up `tsParticles` and the plugin like thi
|
|
|
42
42
|
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
43
|
|
|
44
44
|
```shell
|
|
45
|
-
$ npm install tsparticles
|
|
45
|
+
$ npm install @tsparticles/plugin-infection
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
or
|
|
49
49
|
|
|
50
50
|
```shell
|
|
51
|
-
$ yarn add tsparticles
|
|
51
|
+
$ yarn add @tsparticles/plugin-infection
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
Then you need to import it in the app, like this:
|
|
55
55
|
|
|
56
56
|
```javascript
|
|
57
|
-
const { tsParticles } = require("tsparticles
|
|
58
|
-
const { loadInfectionPlugin } = require("tsparticles
|
|
57
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
58
|
+
const { loadInfectionPlugin } = require("@tsparticles/plugin-infection");
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
(async () => {
|
|
61
|
+
await loadInfectionPlugin(tsParticles);
|
|
62
|
+
})();
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
or
|
|
64
66
|
|
|
65
67
|
```javascript
|
|
66
|
-
import { tsParticles } from "tsparticles
|
|
67
|
-
import { loadInfectionPlugin } from "tsparticles
|
|
68
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
69
|
+
import { loadInfectionPlugin } from "@tsparticles/plugin-infection";
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
(async () => {
|
|
72
|
+
await loadInfectionPlugin(tsParticles);
|
|
73
|
+
})();
|
|
70
74
|
```
|
package/browser/Infecter.js
CHANGED
|
@@ -1,97 +1,95 @@
|
|
|
1
1
|
export class Infecter {
|
|
2
2
|
constructor(container) {
|
|
3
|
-
this.
|
|
3
|
+
this._nextInfectionStage = (particle) => {
|
|
4
|
+
const infectionOptions = this._container.actualOptions.infection, { infection } = particle;
|
|
5
|
+
if (!infectionOptions || !infection) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const stagesCount = infectionOptions.stages.length;
|
|
9
|
+
if (stagesCount <= 0 || infection.stage === undefined) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
infection.time = 0;
|
|
13
|
+
if (stagesCount <= ++infection.stage) {
|
|
14
|
+
if (infectionOptions.cure) {
|
|
15
|
+
delete infection.stage;
|
|
16
|
+
delete infection.time;
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
infection.stage = 0;
|
|
21
|
+
infection.time = 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
this._container = container;
|
|
4
26
|
}
|
|
5
27
|
startInfection(particle, stage) {
|
|
6
|
-
const
|
|
7
|
-
if (!
|
|
28
|
+
const infectionOptions = this._container.actualOptions.infection, { infection } = particle;
|
|
29
|
+
if (!infectionOptions || !infection) {
|
|
8
30
|
return;
|
|
9
31
|
}
|
|
10
|
-
const stages =
|
|
32
|
+
const stages = infectionOptions.stages, stagesCount = stages.length;
|
|
11
33
|
if (stage > stagesCount || stage < 0) {
|
|
12
34
|
return;
|
|
13
35
|
}
|
|
14
|
-
|
|
15
|
-
|
|
36
|
+
infection.delay = 0;
|
|
37
|
+
infection.delayStage = stage;
|
|
16
38
|
}
|
|
17
39
|
updateInfection(particle, delta) {
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
40
|
+
const infectionOptions = this._container.actualOptions.infection, { infection } = particle;
|
|
41
|
+
if (!infectionOptions || !infection) {
|
|
20
42
|
return;
|
|
21
43
|
}
|
|
22
|
-
const stages =
|
|
23
|
-
if (
|
|
24
|
-
const stage =
|
|
44
|
+
const stages = infectionOptions.stages, stagesCount = stages.length;
|
|
45
|
+
if (infection.delay !== undefined && infection.delayStage !== undefined) {
|
|
46
|
+
const stage = infection.delayStage;
|
|
25
47
|
if (stage > stagesCount || stage < 0) {
|
|
26
48
|
return;
|
|
27
49
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
delete
|
|
32
|
-
delete
|
|
50
|
+
if (infection.delay >= infectionOptions.delay * 1000) {
|
|
51
|
+
infection.stage = stage;
|
|
52
|
+
infection.time = 0;
|
|
53
|
+
delete infection.delay;
|
|
54
|
+
delete infection.delayStage;
|
|
33
55
|
}
|
|
34
56
|
else {
|
|
35
|
-
|
|
57
|
+
infection.delay += delta;
|
|
36
58
|
}
|
|
37
59
|
}
|
|
38
60
|
else {
|
|
39
|
-
delete
|
|
40
|
-
delete
|
|
61
|
+
delete infection.delay;
|
|
62
|
+
delete infection.delayStage;
|
|
41
63
|
}
|
|
42
|
-
if (
|
|
43
|
-
const infectionStage = stages[
|
|
64
|
+
if (infection.stage !== undefined && infection.time !== undefined) {
|
|
65
|
+
const infectionStage = stages[infection.stage];
|
|
44
66
|
if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
|
|
45
|
-
if (
|
|
46
|
-
this.
|
|
67
|
+
if (infection.time > infectionStage.duration * 1000) {
|
|
68
|
+
this._nextInfectionStage(particle);
|
|
47
69
|
}
|
|
48
70
|
else {
|
|
49
|
-
|
|
71
|
+
infection.time += delta;
|
|
50
72
|
}
|
|
51
73
|
}
|
|
52
74
|
else {
|
|
53
|
-
|
|
75
|
+
infection.time += delta;
|
|
54
76
|
}
|
|
55
77
|
}
|
|
56
78
|
else {
|
|
57
|
-
delete
|
|
58
|
-
delete
|
|
79
|
+
delete infection.stage;
|
|
80
|
+
delete infection.time;
|
|
59
81
|
}
|
|
60
82
|
}
|
|
61
83
|
updateInfectionStage(particle, stage) {
|
|
62
|
-
const options = this.
|
|
63
|
-
if (!options.infection || !
|
|
84
|
+
const options = this._container.actualOptions, { infection } = particle;
|
|
85
|
+
if (!options.infection || !infection) {
|
|
64
86
|
return;
|
|
65
87
|
}
|
|
66
88
|
const stagesCount = options.infection.stages.length;
|
|
67
|
-
if (stage > stagesCount ||
|
|
68
|
-
stage < 0 ||
|
|
69
|
-
(particle.infection.stage !== undefined && particle.infection.stage > stage)) {
|
|
89
|
+
if (stage > stagesCount || stage < 0 || (infection.stage !== undefined && infection.stage > stage)) {
|
|
70
90
|
return;
|
|
71
91
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
nextInfectionStage(particle) {
|
|
76
|
-
const options = this.container.actualOptions;
|
|
77
|
-
if (!options.infection || !particle.infection) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const stagesCount = options.infection.stages.length;
|
|
81
|
-
if (stagesCount <= 0 || particle.infection.stage === undefined) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
particle.infection.time = 0;
|
|
85
|
-
if (stagesCount <= ++particle.infection.stage) {
|
|
86
|
-
if (options.infection.cure) {
|
|
87
|
-
delete particle.infection.stage;
|
|
88
|
-
delete particle.infection.time;
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
particle.infection.stage = 0;
|
|
93
|
-
particle.infection.time = 0;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
92
|
+
infection.stage = stage;
|
|
93
|
+
infection.time = 0;
|
|
96
94
|
}
|
|
97
95
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Infecter } from "./Infecter";
|
|
2
1
|
import { itemFromArray } from "@tsparticles/engine";
|
|
2
|
+
import { Infecter } from "./Infecter.js";
|
|
3
3
|
export class InfectionInstance {
|
|
4
4
|
constructor(container) {
|
|
5
|
-
this.
|
|
6
|
-
this.
|
|
5
|
+
this._container = container;
|
|
6
|
+
this._container.infecter = new Infecter(this._container);
|
|
7
7
|
}
|
|
8
8
|
particleFillColor(particle) {
|
|
9
|
-
const options = this.
|
|
9
|
+
const options = this._container.actualOptions;
|
|
10
10
|
if (!particle.infection || !options.infection) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
@@ -17,13 +17,12 @@ export class InfectionInstance {
|
|
|
17
17
|
return this.particleFillColor(particle);
|
|
18
18
|
}
|
|
19
19
|
particlesSetup() {
|
|
20
|
-
|
|
21
|
-
const options = this.container.actualOptions;
|
|
20
|
+
const options = this._container.actualOptions;
|
|
22
21
|
if (!options.infection) {
|
|
23
22
|
return;
|
|
24
23
|
}
|
|
25
24
|
for (let i = 0; i < options.infection.infections; i++) {
|
|
26
|
-
const notInfected = this.
|
|
25
|
+
const notInfected = this._container.particles.filter((p) => {
|
|
27
26
|
const infP = p;
|
|
28
27
|
if (!infP.infection) {
|
|
29
28
|
infP.infection = {};
|
|
@@ -31,7 +30,7 @@ export class InfectionInstance {
|
|
|
31
30
|
return infP.infection.stage === undefined;
|
|
32
31
|
});
|
|
33
32
|
const infected = itemFromArray(notInfected);
|
|
34
|
-
|
|
33
|
+
this._container.infecter?.startInfection(infected, 0);
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
}
|
|
@@ -8,46 +8,43 @@ export class ParticlesInfecter extends ParticlesInteractorBase {
|
|
|
8
8
|
init() {
|
|
9
9
|
}
|
|
10
10
|
async interact(p1, delta) {
|
|
11
|
-
var _a, _b, _c, _d, _e;
|
|
12
11
|
const infecter = this.container.infecter;
|
|
13
12
|
if (!infecter) {
|
|
14
13
|
return;
|
|
15
14
|
}
|
|
16
15
|
infecter.updateInfection(p1, delta.value);
|
|
17
|
-
if (
|
|
16
|
+
if (p1.infection?.stage === undefined) {
|
|
18
17
|
return;
|
|
19
18
|
}
|
|
20
19
|
const container = this.container, options = container.actualOptions, infectionOptions = options.infection;
|
|
21
|
-
if (!
|
|
20
|
+
if (!infectionOptions?.enable || infectionOptions.stages.length < 1) {
|
|
22
21
|
return;
|
|
23
22
|
}
|
|
24
|
-
const infectionStage1 = infectionOptions.stages[p1.infection.stage], pxRatio = container.retina.pixelRatio, radius = p1.getRadius() * 2 + infectionStage1.radius * pxRatio, pos = p1.getPosition(), infectedStage1 =
|
|
23
|
+
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;
|
|
25
24
|
for (const p2 of query) {
|
|
26
25
|
const infP2 = p2;
|
|
27
26
|
if (infP2 === p1 ||
|
|
28
27
|
infP2.destroyed ||
|
|
29
28
|
infP2.spawning ||
|
|
30
|
-
!(
|
|
29
|
+
!(infP2.infection?.stage === undefined || infP2.infection.stage !== p1.infection.stage) ||
|
|
30
|
+
getRandom() >= infections / neighbors) {
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
infecter.updateInfectionStage(p1, infectedStage2);
|
|
44
|
-
}
|
|
33
|
+
if (infP2.infection?.stage === undefined) {
|
|
34
|
+
infecter.startInfection(infP2, infectedStage1);
|
|
35
|
+
}
|
|
36
|
+
else if (infP2.infection.stage < p1.infection.stage) {
|
|
37
|
+
infecter.updateInfectionStage(infP2, infectedStage1);
|
|
38
|
+
}
|
|
39
|
+
else if (infP2.infection.stage > p1.infection.stage) {
|
|
40
|
+
const infectionStage2 = infectionOptions.stages[infP2.infection.stage];
|
|
41
|
+
const infectedStage2 = infectionStage2?.infectedStage ?? infP2.infection.stage;
|
|
42
|
+
infecter.updateInfectionStage(p1, infectedStage2);
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
isEnabled() {
|
|
49
|
-
|
|
50
|
-
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;
|
|
47
|
+
return this.container.actualOptions?.infection?.enable ?? false;
|
|
51
48
|
}
|
|
52
49
|
reset() {
|
|
53
50
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Infection } from "./Options/Classes/Infection";
|
|
2
|
-
import { InfectionInstance } from "./InfectionInstance";
|
|
3
|
-
import { ParticlesInfecter } from "./ParticlesInfecter";
|
|
1
|
+
import { Infection } from "./Options/Classes/Infection.js";
|
|
2
|
+
import { InfectionInstance } from "./InfectionInstance.js";
|
|
3
|
+
import { ParticlesInfecter } from "./ParticlesInfecter.js";
|
|
4
4
|
class InfectionPlugin {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.id = "infection";
|
|
@@ -9,24 +9,23 @@ class InfectionPlugin {
|
|
|
9
9
|
return new InfectionInstance(container);
|
|
10
10
|
}
|
|
11
11
|
loadOptions(options, source) {
|
|
12
|
-
if (!this.needsPlugin(source)) {
|
|
12
|
+
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
let infectionOptions = options.infection;
|
|
16
|
-
if (
|
|
16
|
+
if (infectionOptions?.load === undefined) {
|
|
17
17
|
options.infection = infectionOptions = new Infection();
|
|
18
18
|
}
|
|
19
|
-
infectionOptions.load(source
|
|
19
|
+
infectionOptions.load(source?.infection);
|
|
20
20
|
}
|
|
21
21
|
needsPlugin(options) {
|
|
22
|
-
|
|
23
|
-
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;
|
|
22
|
+
return options?.infection?.enable ?? false;
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
|
-
export async function loadInfectionPlugin(engine) {
|
|
25
|
+
export async function loadInfectionPlugin(engine, refresh = true) {
|
|
27
26
|
const plugin = new InfectionPlugin();
|
|
28
|
-
await engine.addPlugin(plugin);
|
|
29
|
-
await engine.addInteractor("particlesInfection", (container) => new ParticlesInfecter(container));
|
|
27
|
+
await engine.addPlugin(plugin, refresh);
|
|
28
|
+
await engine.addInteractor("particlesInfection", (container) => new ParticlesInfecter(container), refresh);
|
|
30
29
|
}
|
|
31
|
-
export * from "./Options/Interfaces/IInfection";
|
|
32
|
-
export * from "./Options/Interfaces/IInfectionStage";
|
|
30
|
+
export * from "./Options/Interfaces/IInfection.js";
|
|
31
|
+
export * from "./Options/Interfaces/IInfectionStage.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/cjs/Infecter.js
CHANGED
|
@@ -3,99 +3,97 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Infecter = void 0;
|
|
4
4
|
class Infecter {
|
|
5
5
|
constructor(container) {
|
|
6
|
-
this.
|
|
6
|
+
this._nextInfectionStage = (particle) => {
|
|
7
|
+
const infectionOptions = this._container.actualOptions.infection, { infection } = particle;
|
|
8
|
+
if (!infectionOptions || !infection) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const stagesCount = infectionOptions.stages.length;
|
|
12
|
+
if (stagesCount <= 0 || infection.stage === undefined) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
infection.time = 0;
|
|
16
|
+
if (stagesCount <= ++infection.stage) {
|
|
17
|
+
if (infectionOptions.cure) {
|
|
18
|
+
delete infection.stage;
|
|
19
|
+
delete infection.time;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
infection.stage = 0;
|
|
24
|
+
infection.time = 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
this._container = container;
|
|
7
29
|
}
|
|
8
30
|
startInfection(particle, stage) {
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
31
|
+
const infectionOptions = this._container.actualOptions.infection, { infection } = particle;
|
|
32
|
+
if (!infectionOptions || !infection) {
|
|
11
33
|
return;
|
|
12
34
|
}
|
|
13
|
-
const stages =
|
|
35
|
+
const stages = infectionOptions.stages, stagesCount = stages.length;
|
|
14
36
|
if (stage > stagesCount || stage < 0) {
|
|
15
37
|
return;
|
|
16
38
|
}
|
|
17
|
-
|
|
18
|
-
|
|
39
|
+
infection.delay = 0;
|
|
40
|
+
infection.delayStage = stage;
|
|
19
41
|
}
|
|
20
42
|
updateInfection(particle, delta) {
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
43
|
+
const infectionOptions = this._container.actualOptions.infection, { infection } = particle;
|
|
44
|
+
if (!infectionOptions || !infection) {
|
|
23
45
|
return;
|
|
24
46
|
}
|
|
25
|
-
const stages =
|
|
26
|
-
if (
|
|
27
|
-
const stage =
|
|
47
|
+
const stages = infectionOptions.stages, stagesCount = stages.length;
|
|
48
|
+
if (infection.delay !== undefined && infection.delayStage !== undefined) {
|
|
49
|
+
const stage = infection.delayStage;
|
|
28
50
|
if (stage > stagesCount || stage < 0) {
|
|
29
51
|
return;
|
|
30
52
|
}
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
delete
|
|
35
|
-
delete
|
|
53
|
+
if (infection.delay >= infectionOptions.delay * 1000) {
|
|
54
|
+
infection.stage = stage;
|
|
55
|
+
infection.time = 0;
|
|
56
|
+
delete infection.delay;
|
|
57
|
+
delete infection.delayStage;
|
|
36
58
|
}
|
|
37
59
|
else {
|
|
38
|
-
|
|
60
|
+
infection.delay += delta;
|
|
39
61
|
}
|
|
40
62
|
}
|
|
41
63
|
else {
|
|
42
|
-
delete
|
|
43
|
-
delete
|
|
64
|
+
delete infection.delay;
|
|
65
|
+
delete infection.delayStage;
|
|
44
66
|
}
|
|
45
|
-
if (
|
|
46
|
-
const infectionStage = stages[
|
|
67
|
+
if (infection.stage !== undefined && infection.time !== undefined) {
|
|
68
|
+
const infectionStage = stages[infection.stage];
|
|
47
69
|
if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
|
|
48
|
-
if (
|
|
49
|
-
this.
|
|
70
|
+
if (infection.time > infectionStage.duration * 1000) {
|
|
71
|
+
this._nextInfectionStage(particle);
|
|
50
72
|
}
|
|
51
73
|
else {
|
|
52
|
-
|
|
74
|
+
infection.time += delta;
|
|
53
75
|
}
|
|
54
76
|
}
|
|
55
77
|
else {
|
|
56
|
-
|
|
78
|
+
infection.time += delta;
|
|
57
79
|
}
|
|
58
80
|
}
|
|
59
81
|
else {
|
|
60
|
-
delete
|
|
61
|
-
delete
|
|
82
|
+
delete infection.stage;
|
|
83
|
+
delete infection.time;
|
|
62
84
|
}
|
|
63
85
|
}
|
|
64
86
|
updateInfectionStage(particle, stage) {
|
|
65
|
-
const options = this.
|
|
66
|
-
if (!options.infection || !
|
|
87
|
+
const options = this._container.actualOptions, { infection } = particle;
|
|
88
|
+
if (!options.infection || !infection) {
|
|
67
89
|
return;
|
|
68
90
|
}
|
|
69
91
|
const stagesCount = options.infection.stages.length;
|
|
70
|
-
if (stage > stagesCount ||
|
|
71
|
-
stage < 0 ||
|
|
72
|
-
(particle.infection.stage !== undefined && particle.infection.stage > stage)) {
|
|
92
|
+
if (stage > stagesCount || stage < 0 || (infection.stage !== undefined && infection.stage > stage)) {
|
|
73
93
|
return;
|
|
74
94
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
nextInfectionStage(particle) {
|
|
79
|
-
const options = this.container.actualOptions;
|
|
80
|
-
if (!options.infection || !particle.infection) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const stagesCount = options.infection.stages.length;
|
|
84
|
-
if (stagesCount <= 0 || particle.infection.stage === undefined) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
particle.infection.time = 0;
|
|
88
|
-
if (stagesCount <= ++particle.infection.stage) {
|
|
89
|
-
if (options.infection.cure) {
|
|
90
|
-
delete particle.infection.stage;
|
|
91
|
-
delete particle.infection.time;
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
particle.infection.stage = 0;
|
|
96
|
-
particle.infection.time = 0;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
95
|
+
infection.stage = stage;
|
|
96
|
+
infection.time = 0;
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
99
|
exports.Infecter = Infecter;
|
package/cjs/InfectionInstance.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InfectionInstance = void 0;
|
|
4
|
-
const Infecter_1 = require("./Infecter");
|
|
5
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const Infecter_js_1 = require("./Infecter.js");
|
|
6
6
|
class InfectionInstance {
|
|
7
7
|
constructor(container) {
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
8
|
+
this._container = container;
|
|
9
|
+
this._container.infecter = new Infecter_js_1.Infecter(this._container);
|
|
10
10
|
}
|
|
11
11
|
particleFillColor(particle) {
|
|
12
|
-
const options = this.
|
|
12
|
+
const options = this._container.actualOptions;
|
|
13
13
|
if (!particle.infection || !options.infection) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
@@ -20,13 +20,12 @@ class InfectionInstance {
|
|
|
20
20
|
return this.particleFillColor(particle);
|
|
21
21
|
}
|
|
22
22
|
particlesSetup() {
|
|
23
|
-
|
|
24
|
-
const options = this.container.actualOptions;
|
|
23
|
+
const options = this._container.actualOptions;
|
|
25
24
|
if (!options.infection) {
|
|
26
25
|
return;
|
|
27
26
|
}
|
|
28
27
|
for (let i = 0; i < options.infection.infections; i++) {
|
|
29
|
-
const notInfected = this.
|
|
28
|
+
const notInfected = this._container.particles.filter((p) => {
|
|
30
29
|
const infP = p;
|
|
31
30
|
if (!infP.infection) {
|
|
32
31
|
infP.infection = {};
|
|
@@ -34,7 +33,7 @@ class InfectionInstance {
|
|
|
34
33
|
return infP.infection.stage === undefined;
|
|
35
34
|
});
|
|
36
35
|
const infected = (0, engine_1.itemFromArray)(notInfected);
|
|
37
|
-
|
|
36
|
+
this._container.infecter?.startInfection(infected, 0);
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Infection = void 0;
|
|
4
|
-
const
|
|
4
|
+
const InfectionStage_js_1 = require("./InfectionStage.js");
|
|
5
5
|
class Infection {
|
|
6
6
|
constructor() {
|
|
7
7
|
this.cure = false;
|
|
@@ -30,7 +30,7 @@ class Infection {
|
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
this.stages = data.stages.map((t) => {
|
|
33
|
-
const s = new
|
|
33
|
+
const s = new InfectionStage_js_1.InfectionStage();
|
|
34
34
|
s.load(t);
|
|
35
35
|
return s;
|
|
36
36
|
});
|