@tsparticles/plugin-infection 3.0.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/Infecter.js +97 -0
- package/browser/InfectionInstance.js +37 -0
- package/browser/Options/Classes/Infection.js +35 -0
- package/browser/Options/Classes/InfectionStage.js +25 -0
- package/browser/Options/Interfaces/IInfection.js +1 -0
- package/browser/Options/Interfaces/IInfectionStage.js +1 -0
- package/browser/ParticlesInfecter.js +54 -0
- package/browser/Types.js +1 -0
- package/browser/index.js +32 -0
- package/cjs/Infecter.js +101 -0
- package/cjs/InfectionInstance.js +41 -0
- package/cjs/Options/Classes/Infection.js +39 -0
- package/cjs/Options/Classes/InfectionStage.js +29 -0
- package/cjs/Options/Interfaces/IInfection.js +2 -0
- package/cjs/Options/Interfaces/IInfectionStage.js +2 -0
- package/cjs/ParticlesInfecter.js +69 -0
- package/cjs/Types.js +2 -0
- package/cjs/index.js +61 -0
- package/esm/Infecter.js +97 -0
- package/esm/InfectionInstance.js +37 -0
- package/esm/Options/Classes/Infection.js +35 -0
- package/esm/Options/Classes/InfectionStage.js +25 -0
- package/esm/Options/Interfaces/IInfection.js +1 -0
- package/esm/Options/Interfaces/IInfectionStage.js +1 -0
- package/esm/ParticlesInfecter.js +54 -0
- package/esm/Types.js +1 -0
- package/esm/index.js +32 -0
- package/package.json +91 -0
- package/report.html +39 -0
- package/tsparticles.plugin.infection.js +387 -0
- package/tsparticles.plugin.infection.min.js +2 -0
- package/tsparticles.plugin.infection.min.js.LICENSE.txt +8 -0
- package/types/Infecter.d.ts +9 -0
- package/types/InfectionInstance.d.ts +9 -0
- package/types/Options/Classes/Infection.d.ts +12 -0
- package/types/Options/Classes/InfectionStage.d.ts +12 -0
- package/types/Options/Interfaces/IInfection.d.ts +8 -0
- package/types/Options/Interfaces/IInfectionStage.d.ts +8 -0
- package/types/ParticlesInfecter.d.ts +11 -0
- package/types/Types.d.ts +24 -0
- package/types/index.d.ts +4 -0
- package/umd/Infecter.js +111 -0
- package/umd/InfectionInstance.js +51 -0
- package/umd/Options/Classes/Infection.js +49 -0
- package/umd/Options/Classes/InfectionStage.js +39 -0
- package/umd/Options/Interfaces/IInfection.js +12 -0
- package/umd/Options/Interfaces/IInfectionStage.js +12 -0
- package/umd/ParticlesInfecter.js +68 -0
- package/umd/Types.js +12 -0
- package/umd/index.js +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Matteo Bruni
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles Infection Plugin
|
|
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
|
+
|
|
9
|
+
[tsParticles](https://github.com/matteobruni/tsparticles) plugin for particles infection simulation effect.
|
|
10
|
+
|
|
11
|
+
## How to use it
|
|
12
|
+
|
|
13
|
+
### CDN / Vanilla JS / jQuery
|
|
14
|
+
|
|
15
|
+
The CDN/Vanilla version JS has one required file in vanilla configuration:
|
|
16
|
+
|
|
17
|
+
Including the `tsparticles.plugin.infection.min.js` file will export the function to load the plugin:
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
loadInfectionPlugin
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
|
|
25
|
+
Once the scripts are loaded you can set up `tsParticles` and the plugin like this:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
(async () => {
|
|
29
|
+
await loadInfectionPlugin();
|
|
30
|
+
|
|
31
|
+
await tsParticles.load({
|
|
32
|
+
id: "tsparticles",
|
|
33
|
+
options: {
|
|
34
|
+
/* options */
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
})();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### ESM / CommonJS
|
|
41
|
+
|
|
42
|
+
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
$ npm install tsparticles-plugin-infection
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
$ yarn add tsparticles-plugin-infection
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Then you need to import it in the app, like this:
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const { tsParticles } = require("tsparticles-engine");
|
|
58
|
+
const { loadInfectionPlugin } = require("tsparticles-plugin-infection");
|
|
59
|
+
|
|
60
|
+
loadInfectionPlugin(tsParticles);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
or
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { tsParticles } from "tsparticles-engine";
|
|
67
|
+
import { loadInfectionPlugin } from "tsparticles-plugin-infection";
|
|
68
|
+
|
|
69
|
+
loadInfectionPlugin(tsParticles);
|
|
70
|
+
```
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export class Infecter {
|
|
2
|
+
constructor(container) {
|
|
3
|
+
this.container = container;
|
|
4
|
+
}
|
|
5
|
+
startInfection(particle, stage) {
|
|
6
|
+
const options = this.container.actualOptions;
|
|
7
|
+
if (!options.infection || !particle.infection) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const stages = options.infection.stages, stagesCount = stages.length;
|
|
11
|
+
if (stage > stagesCount || stage < 0) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
particle.infection.delay = 0;
|
|
15
|
+
particle.infection.delayStage = stage;
|
|
16
|
+
}
|
|
17
|
+
updateInfection(particle, delta) {
|
|
18
|
+
const infection = this.container.actualOptions.infection;
|
|
19
|
+
if (!infection || !particle.infection) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const stages = infection.stages, stagesCount = stages.length;
|
|
23
|
+
if (particle.infection.delay !== undefined && particle.infection.delayStage !== undefined) {
|
|
24
|
+
const stage = particle.infection.delayStage;
|
|
25
|
+
if (stage > stagesCount || stage < 0) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (particle.infection.delay >= infection.delay * 1000) {
|
|
29
|
+
particle.infection.stage = stage;
|
|
30
|
+
particle.infection.time = 0;
|
|
31
|
+
delete particle.infection.delay;
|
|
32
|
+
delete particle.infection.delayStage;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
particle.infection.delay += delta;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
delete particle.infection.delay;
|
|
40
|
+
delete particle.infection.delayStage;
|
|
41
|
+
}
|
|
42
|
+
if (particle.infection.stage !== undefined && particle.infection.time !== undefined) {
|
|
43
|
+
const infectionStage = stages[particle.infection.stage];
|
|
44
|
+
if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
|
|
45
|
+
if (particle.infection.time > infectionStage.duration * 1000) {
|
|
46
|
+
this.nextInfectionStage(particle);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
particle.infection.time += delta;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
particle.infection.time += delta;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
delete particle.infection.stage;
|
|
58
|
+
delete particle.infection.time;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
updateInfectionStage(particle, stage) {
|
|
62
|
+
const options = this.container.actualOptions;
|
|
63
|
+
if (!options.infection || !particle.infection) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const stagesCount = options.infection.stages.length;
|
|
67
|
+
if (stage > stagesCount ||
|
|
68
|
+
stage < 0 ||
|
|
69
|
+
(particle.infection.stage !== undefined && particle.infection.stage > stage)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
particle.infection.stage = stage;
|
|
73
|
+
particle.infection.time = 0;
|
|
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
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Infecter } from "./Infecter";
|
|
2
|
+
import { itemFromArray } from "@tsparticles/engine";
|
|
3
|
+
export class InfectionInstance {
|
|
4
|
+
constructor(container) {
|
|
5
|
+
this.container = container;
|
|
6
|
+
this.container.infecter = new Infecter(this.container);
|
|
7
|
+
}
|
|
8
|
+
particleFillColor(particle) {
|
|
9
|
+
const options = this.container.actualOptions;
|
|
10
|
+
if (!particle.infection || !options.infection) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const infectionStage = particle.infection.stage, infection = options.infection, infectionStages = infection.stages;
|
|
14
|
+
return infectionStage !== undefined ? infectionStages[infectionStage].color : undefined;
|
|
15
|
+
}
|
|
16
|
+
particleStrokeColor(particle) {
|
|
17
|
+
return this.particleFillColor(particle);
|
|
18
|
+
}
|
|
19
|
+
particlesSetup() {
|
|
20
|
+
var _a;
|
|
21
|
+
const options = this.container.actualOptions;
|
|
22
|
+
if (!options.infection) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
for (let i = 0; i < options.infection.infections; i++) {
|
|
26
|
+
const notInfected = this.container.particles.array.filter((p) => {
|
|
27
|
+
const infP = p;
|
|
28
|
+
if (!infP.infection) {
|
|
29
|
+
infP.infection = {};
|
|
30
|
+
}
|
|
31
|
+
return infP.infection.stage === undefined;
|
|
32
|
+
});
|
|
33
|
+
const infected = itemFromArray(notInfected);
|
|
34
|
+
(_a = this.container.infecter) === null || _a === void 0 ? void 0 : _a.startInfection(infected, 0);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { InfectionStage } from "./InfectionStage";
|
|
2
|
+
export class Infection {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.cure = false;
|
|
5
|
+
this.delay = 0;
|
|
6
|
+
this.enable = false;
|
|
7
|
+
this.infections = 0;
|
|
8
|
+
this.stages = [];
|
|
9
|
+
}
|
|
10
|
+
load(data) {
|
|
11
|
+
if (data === undefined) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (data.cure !== undefined) {
|
|
15
|
+
this.cure = data.cure;
|
|
16
|
+
}
|
|
17
|
+
if (data.delay !== undefined) {
|
|
18
|
+
this.delay = data.delay;
|
|
19
|
+
}
|
|
20
|
+
if (data.enable !== undefined) {
|
|
21
|
+
this.enable = data.enable;
|
|
22
|
+
}
|
|
23
|
+
if (data.infections !== undefined) {
|
|
24
|
+
this.infections = data.infections;
|
|
25
|
+
}
|
|
26
|
+
if (data.stages === undefined) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this.stages = data.stages.map((t) => {
|
|
30
|
+
const s = new InfectionStage();
|
|
31
|
+
s.load(t);
|
|
32
|
+
return s;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { OptionsColor } from "@tsparticles/engine";
|
|
2
|
+
export class InfectionStage {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.color = new OptionsColor();
|
|
5
|
+
this.color.value = "#ff0000";
|
|
6
|
+
this.radius = 0;
|
|
7
|
+
this.rate = 1;
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (data === undefined) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.color !== undefined) {
|
|
14
|
+
this.color = OptionsColor.create(this.color, data.color);
|
|
15
|
+
}
|
|
16
|
+
this.duration = data.duration;
|
|
17
|
+
this.infectedStage = data.infectedStage;
|
|
18
|
+
if (data.radius !== undefined) {
|
|
19
|
+
this.radius = data.radius;
|
|
20
|
+
}
|
|
21
|
+
if (data.rate !== undefined) {
|
|
22
|
+
this.rate = data.rate;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ParticlesInteractorBase, getRandom } from "@tsparticles/engine";
|
|
2
|
+
export class ParticlesInfecter extends ParticlesInteractorBase {
|
|
3
|
+
constructor(container) {
|
|
4
|
+
super(container);
|
|
5
|
+
}
|
|
6
|
+
clear() {
|
|
7
|
+
}
|
|
8
|
+
init() {
|
|
9
|
+
}
|
|
10
|
+
async interact(p1, delta) {
|
|
11
|
+
var _a, _b, _c, _d, _e;
|
|
12
|
+
const infecter = this.container.infecter;
|
|
13
|
+
if (!infecter) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
infecter.updateInfection(p1, delta.value);
|
|
17
|
+
if (((_a = p1.infection) === null || _a === void 0 ? void 0 : _a.stage) === undefined) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const container = this.container, options = container.actualOptions, infectionOptions = options.infection;
|
|
21
|
+
if (!(infectionOptions === null || infectionOptions === void 0 ? void 0 : infectionOptions.enable) || infectionOptions.stages.length < 1) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
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;
|
|
25
|
+
for (const p2 of query) {
|
|
26
|
+
const infP2 = p2;
|
|
27
|
+
if (infP2 === p1 ||
|
|
28
|
+
infP2.destroyed ||
|
|
29
|
+
infP2.spawning ||
|
|
30
|
+
!(((_c = infP2.infection) === null || _c === void 0 ? void 0 : _c.stage) === undefined || infP2.infection.stage !== p1.infection.stage)) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (getRandom() < infections / neighbors) {
|
|
34
|
+
if (((_d = infP2.infection) === null || _d === void 0 ? void 0 : _d.stage) === undefined) {
|
|
35
|
+
infecter.startInfection(infP2, infectedStage1);
|
|
36
|
+
}
|
|
37
|
+
else if (infP2.infection.stage < p1.infection.stage) {
|
|
38
|
+
infecter.updateInfectionStage(infP2, infectedStage1);
|
|
39
|
+
}
|
|
40
|
+
else if (infP2.infection.stage > p1.infection.stage) {
|
|
41
|
+
const infectionStage2 = infectionOptions.stages[infP2.infection.stage];
|
|
42
|
+
const infectedStage2 = (_e = infectionStage2 === null || infectionStage2 === void 0 ? void 0 : infectionStage2.infectedStage) !== null && _e !== void 0 ? _e : infP2.infection.stage;
|
|
43
|
+
infecter.updateInfectionStage(p1, infectedStage2);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
isEnabled() {
|
|
49
|
+
var _a, _b, _c;
|
|
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;
|
|
51
|
+
}
|
|
52
|
+
reset() {
|
|
53
|
+
}
|
|
54
|
+
}
|
package/browser/Types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Infection } from "./Options/Classes/Infection";
|
|
2
|
+
import { InfectionInstance } from "./InfectionInstance";
|
|
3
|
+
import { ParticlesInfecter } from "./ParticlesInfecter";
|
|
4
|
+
class InfectionPlugin {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.id = "infection";
|
|
7
|
+
}
|
|
8
|
+
getPlugin(container) {
|
|
9
|
+
return new InfectionInstance(container);
|
|
10
|
+
}
|
|
11
|
+
loadOptions(options, source) {
|
|
12
|
+
if (!this.needsPlugin(source)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
let infectionOptions = options.infection;
|
|
16
|
+
if ((infectionOptions === null || infectionOptions === void 0 ? void 0 : infectionOptions.load) === undefined) {
|
|
17
|
+
options.infection = infectionOptions = new Infection();
|
|
18
|
+
}
|
|
19
|
+
infectionOptions.load(source === null || source === void 0 ? void 0 : source.infection);
|
|
20
|
+
}
|
|
21
|
+
needsPlugin(options) {
|
|
22
|
+
var _a, _b;
|
|
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;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export async function loadInfectionPlugin(engine) {
|
|
27
|
+
const plugin = new InfectionPlugin();
|
|
28
|
+
await engine.addPlugin(plugin);
|
|
29
|
+
await engine.addInteractor("particlesInfection", (container) => new ParticlesInfecter(container));
|
|
30
|
+
}
|
|
31
|
+
export * from "./Options/Interfaces/IInfection";
|
|
32
|
+
export * from "./Options/Interfaces/IInfectionStage";
|
package/cjs/Infecter.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Infecter = void 0;
|
|
4
|
+
class Infecter {
|
|
5
|
+
constructor(container) {
|
|
6
|
+
this.container = container;
|
|
7
|
+
}
|
|
8
|
+
startInfection(particle, stage) {
|
|
9
|
+
const options = this.container.actualOptions;
|
|
10
|
+
if (!options.infection || !particle.infection) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const stages = options.infection.stages, stagesCount = stages.length;
|
|
14
|
+
if (stage > stagesCount || stage < 0) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
particle.infection.delay = 0;
|
|
18
|
+
particle.infection.delayStage = stage;
|
|
19
|
+
}
|
|
20
|
+
updateInfection(particle, delta) {
|
|
21
|
+
const infection = this.container.actualOptions.infection;
|
|
22
|
+
if (!infection || !particle.infection) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const stages = infection.stages, stagesCount = stages.length;
|
|
26
|
+
if (particle.infection.delay !== undefined && particle.infection.delayStage !== undefined) {
|
|
27
|
+
const stage = particle.infection.delayStage;
|
|
28
|
+
if (stage > stagesCount || stage < 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (particle.infection.delay >= infection.delay * 1000) {
|
|
32
|
+
particle.infection.stage = stage;
|
|
33
|
+
particle.infection.time = 0;
|
|
34
|
+
delete particle.infection.delay;
|
|
35
|
+
delete particle.infection.delayStage;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
particle.infection.delay += delta;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
delete particle.infection.delay;
|
|
43
|
+
delete particle.infection.delayStage;
|
|
44
|
+
}
|
|
45
|
+
if (particle.infection.stage !== undefined && particle.infection.time !== undefined) {
|
|
46
|
+
const infectionStage = stages[particle.infection.stage];
|
|
47
|
+
if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
|
|
48
|
+
if (particle.infection.time > infectionStage.duration * 1000) {
|
|
49
|
+
this.nextInfectionStage(particle);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
particle.infection.time += delta;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
particle.infection.time += delta;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
delete particle.infection.stage;
|
|
61
|
+
delete particle.infection.time;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
updateInfectionStage(particle, stage) {
|
|
65
|
+
const options = this.container.actualOptions;
|
|
66
|
+
if (!options.infection || !particle.infection) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const stagesCount = options.infection.stages.length;
|
|
70
|
+
if (stage > stagesCount ||
|
|
71
|
+
stage < 0 ||
|
|
72
|
+
(particle.infection.stage !== undefined && particle.infection.stage > stage)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
particle.infection.stage = stage;
|
|
76
|
+
particle.infection.time = 0;
|
|
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
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.Infecter = Infecter;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InfectionInstance = void 0;
|
|
4
|
+
const Infecter_1 = require("./Infecter");
|
|
5
|
+
const engine_1 = require("@tsparticles/engine");
|
|
6
|
+
class InfectionInstance {
|
|
7
|
+
constructor(container) {
|
|
8
|
+
this.container = container;
|
|
9
|
+
this.container.infecter = new Infecter_1.Infecter(this.container);
|
|
10
|
+
}
|
|
11
|
+
particleFillColor(particle) {
|
|
12
|
+
const options = this.container.actualOptions;
|
|
13
|
+
if (!particle.infection || !options.infection) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const infectionStage = particle.infection.stage, infection = options.infection, infectionStages = infection.stages;
|
|
17
|
+
return infectionStage !== undefined ? infectionStages[infectionStage].color : undefined;
|
|
18
|
+
}
|
|
19
|
+
particleStrokeColor(particle) {
|
|
20
|
+
return this.particleFillColor(particle);
|
|
21
|
+
}
|
|
22
|
+
particlesSetup() {
|
|
23
|
+
var _a;
|
|
24
|
+
const options = this.container.actualOptions;
|
|
25
|
+
if (!options.infection) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
for (let i = 0; i < options.infection.infections; i++) {
|
|
29
|
+
const notInfected = this.container.particles.array.filter((p) => {
|
|
30
|
+
const infP = p;
|
|
31
|
+
if (!infP.infection) {
|
|
32
|
+
infP.infection = {};
|
|
33
|
+
}
|
|
34
|
+
return infP.infection.stage === undefined;
|
|
35
|
+
});
|
|
36
|
+
const infected = (0, engine_1.itemFromArray)(notInfected);
|
|
37
|
+
(_a = this.container.infecter) === null || _a === void 0 ? void 0 : _a.startInfection(infected, 0);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.InfectionInstance = InfectionInstance;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Infection = void 0;
|
|
4
|
+
const InfectionStage_1 = require("./InfectionStage");
|
|
5
|
+
class Infection {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.cure = false;
|
|
8
|
+
this.delay = 0;
|
|
9
|
+
this.enable = false;
|
|
10
|
+
this.infections = 0;
|
|
11
|
+
this.stages = [];
|
|
12
|
+
}
|
|
13
|
+
load(data) {
|
|
14
|
+
if (data === undefined) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (data.cure !== undefined) {
|
|
18
|
+
this.cure = data.cure;
|
|
19
|
+
}
|
|
20
|
+
if (data.delay !== undefined) {
|
|
21
|
+
this.delay = data.delay;
|
|
22
|
+
}
|
|
23
|
+
if (data.enable !== undefined) {
|
|
24
|
+
this.enable = data.enable;
|
|
25
|
+
}
|
|
26
|
+
if (data.infections !== undefined) {
|
|
27
|
+
this.infections = data.infections;
|
|
28
|
+
}
|
|
29
|
+
if (data.stages === undefined) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.stages = data.stages.map((t) => {
|
|
33
|
+
const s = new InfectionStage_1.InfectionStage();
|
|
34
|
+
s.load(t);
|
|
35
|
+
return s;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.Infection = Infection;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InfectionStage = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
class InfectionStage {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.color = new engine_1.OptionsColor();
|
|
8
|
+
this.color.value = "#ff0000";
|
|
9
|
+
this.radius = 0;
|
|
10
|
+
this.rate = 1;
|
|
11
|
+
}
|
|
12
|
+
load(data) {
|
|
13
|
+
if (data === undefined) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (data.color !== undefined) {
|
|
17
|
+
this.color = engine_1.OptionsColor.create(this.color, data.color);
|
|
18
|
+
}
|
|
19
|
+
this.duration = data.duration;
|
|
20
|
+
this.infectedStage = data.infectedStage;
|
|
21
|
+
if (data.radius !== undefined) {
|
|
22
|
+
this.radius = data.radius;
|
|
23
|
+
}
|
|
24
|
+
if (data.rate !== undefined) {
|
|
25
|
+
this.rate = data.rate;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.InfectionStage = InfectionStage;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ParticlesInfecter = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
class ParticlesInfecter extends engine_1.ParticlesInteractorBase {
|
|
15
|
+
constructor(container) {
|
|
16
|
+
super(container);
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
}
|
|
20
|
+
init() {
|
|
21
|
+
}
|
|
22
|
+
interact(p1, delta) {
|
|
23
|
+
var _a, _b, _c, _d, _e;
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const infecter = this.container.infecter;
|
|
26
|
+
if (!infecter) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
infecter.updateInfection(p1, delta.value);
|
|
30
|
+
if (((_a = p1.infection) === null || _a === void 0 ? void 0 : _a.stage) === undefined) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const container = this.container, options = container.actualOptions, infectionOptions = options.infection;
|
|
34
|
+
if (!(infectionOptions === null || infectionOptions === void 0 ? void 0 : infectionOptions.enable) || infectionOptions.stages.length < 1) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
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;
|
|
38
|
+
for (const p2 of query) {
|
|
39
|
+
const infP2 = p2;
|
|
40
|
+
if (infP2 === p1 ||
|
|
41
|
+
infP2.destroyed ||
|
|
42
|
+
infP2.spawning ||
|
|
43
|
+
!(((_c = infP2.infection) === null || _c === void 0 ? void 0 : _c.stage) === undefined || infP2.infection.stage !== p1.infection.stage)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if ((0, engine_1.getRandom)() < infections / neighbors) {
|
|
47
|
+
if (((_d = infP2.infection) === null || _d === void 0 ? void 0 : _d.stage) === undefined) {
|
|
48
|
+
infecter.startInfection(infP2, infectedStage1);
|
|
49
|
+
}
|
|
50
|
+
else if (infP2.infection.stage < p1.infection.stage) {
|
|
51
|
+
infecter.updateInfectionStage(infP2, infectedStage1);
|
|
52
|
+
}
|
|
53
|
+
else if (infP2.infection.stage > p1.infection.stage) {
|
|
54
|
+
const infectionStage2 = infectionOptions.stages[infP2.infection.stage];
|
|
55
|
+
const infectedStage2 = (_e = infectionStage2 === null || infectionStage2 === void 0 ? void 0 : infectionStage2.infectedStage) !== null && _e !== void 0 ? _e : infP2.infection.stage;
|
|
56
|
+
infecter.updateInfectionStage(p1, infectedStage2);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
isEnabled() {
|
|
63
|
+
var _a, _b, _c;
|
|
64
|
+
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;
|
|
65
|
+
}
|
|
66
|
+
reset() {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.ParticlesInfecter = ParticlesInfecter;
|