@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
|
@@ -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
|
|
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
|
|
42
|
+
const s = new InfectionStage_js_1.InfectionStage();
|
|
43
43
|
s.load(t);
|
|
44
44
|
return s;
|
|
45
45
|
});
|
package/umd/ParticlesInfecter.js
CHANGED
|
@@ -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 (
|
|
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 (!
|
|
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 =
|
|
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
|
-
!(
|
|
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 (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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
|
|
28
|
-
const
|
|
29
|
-
const
|
|
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
|
|
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 (
|
|
43
|
-
options.infection = infectionOptions = new
|
|
42
|
+
if (infectionOptions?.load === undefined) {
|
|
43
|
+
options.infection = infectionOptions = new Infection_js_1.Infection();
|
|
44
44
|
}
|
|
45
|
-
infectionOptions.load(source
|
|
45
|
+
infectionOptions.load(source?.infection);
|
|
46
46
|
}
|
|
47
47
|
needsPlugin(options) {
|
|
48
|
-
|
|
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
|
|
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
|
});
|