@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,7 +4,7 @@
|
|
|
4
4
|
* Demo / Generator : https://particles.js.org/
|
|
5
5
|
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
6
|
* How to use? : Check the GitHub README
|
|
7
|
-
* v3.0.0-
|
|
7
|
+
* v3.0.0-beta.1
|
|
8
8
|
*/
|
|
9
9
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
10
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
@@ -91,7 +91,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
91
91
|
|
|
92
92
|
// EXPORTS
|
|
93
93
|
__webpack_require__.d(__webpack_exports__, {
|
|
94
|
-
|
|
94
|
+
loadInfectionPlugin: () => (/* binding */ loadInfectionPlugin)
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
@@ -161,93 +161,105 @@ class Infection {
|
|
|
161
161
|
;// CONCATENATED MODULE: ./dist/browser/Infecter.js
|
|
162
162
|
class Infecter {
|
|
163
163
|
constructor(container) {
|
|
164
|
-
this.
|
|
164
|
+
this._nextInfectionStage = particle => {
|
|
165
|
+
const infectionOptions = this._container.actualOptions.infection,
|
|
166
|
+
{
|
|
167
|
+
infection
|
|
168
|
+
} = particle;
|
|
169
|
+
if (!infectionOptions || !infection) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const stagesCount = infectionOptions.stages.length;
|
|
173
|
+
if (stagesCount <= 0 || infection.stage === undefined) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
infection.time = 0;
|
|
177
|
+
if (stagesCount <= ++infection.stage) {
|
|
178
|
+
if (infectionOptions.cure) {
|
|
179
|
+
delete infection.stage;
|
|
180
|
+
delete infection.time;
|
|
181
|
+
return;
|
|
182
|
+
} else {
|
|
183
|
+
infection.stage = 0;
|
|
184
|
+
infection.time = 0;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
this._container = container;
|
|
165
189
|
}
|
|
166
190
|
startInfection(particle, stage) {
|
|
167
|
-
const
|
|
168
|
-
|
|
191
|
+
const infectionOptions = this._container.actualOptions.infection,
|
|
192
|
+
{
|
|
193
|
+
infection
|
|
194
|
+
} = particle;
|
|
195
|
+
if (!infectionOptions || !infection) {
|
|
169
196
|
return;
|
|
170
197
|
}
|
|
171
|
-
const stages =
|
|
198
|
+
const stages = infectionOptions.stages,
|
|
172
199
|
stagesCount = stages.length;
|
|
173
200
|
if (stage > stagesCount || stage < 0) {
|
|
174
201
|
return;
|
|
175
202
|
}
|
|
176
|
-
|
|
177
|
-
|
|
203
|
+
infection.delay = 0;
|
|
204
|
+
infection.delayStage = stage;
|
|
178
205
|
}
|
|
179
206
|
updateInfection(particle, delta) {
|
|
180
|
-
const
|
|
181
|
-
|
|
207
|
+
const infectionOptions = this._container.actualOptions.infection,
|
|
208
|
+
{
|
|
209
|
+
infection
|
|
210
|
+
} = particle;
|
|
211
|
+
if (!infectionOptions || !infection) {
|
|
182
212
|
return;
|
|
183
213
|
}
|
|
184
|
-
const stages =
|
|
214
|
+
const stages = infectionOptions.stages,
|
|
185
215
|
stagesCount = stages.length;
|
|
186
|
-
if (
|
|
187
|
-
const stage =
|
|
216
|
+
if (infection.delay !== undefined && infection.delayStage !== undefined) {
|
|
217
|
+
const stage = infection.delayStage;
|
|
188
218
|
if (stage > stagesCount || stage < 0) {
|
|
189
219
|
return;
|
|
190
220
|
}
|
|
191
|
-
if (
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
delete
|
|
195
|
-
delete
|
|
221
|
+
if (infection.delay >= infectionOptions.delay * 1000) {
|
|
222
|
+
infection.stage = stage;
|
|
223
|
+
infection.time = 0;
|
|
224
|
+
delete infection.delay;
|
|
225
|
+
delete infection.delayStage;
|
|
196
226
|
} else {
|
|
197
|
-
|
|
227
|
+
infection.delay += delta;
|
|
198
228
|
}
|
|
199
229
|
} else {
|
|
200
|
-
delete
|
|
201
|
-
delete
|
|
230
|
+
delete infection.delay;
|
|
231
|
+
delete infection.delayStage;
|
|
202
232
|
}
|
|
203
|
-
if (
|
|
204
|
-
const infectionStage = stages[
|
|
233
|
+
if (infection.stage !== undefined && infection.time !== undefined) {
|
|
234
|
+
const infectionStage = stages[infection.stage];
|
|
205
235
|
if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
|
|
206
|
-
if (
|
|
207
|
-
this.
|
|
236
|
+
if (infection.time > infectionStage.duration * 1000) {
|
|
237
|
+
this._nextInfectionStage(particle);
|
|
208
238
|
} else {
|
|
209
|
-
|
|
239
|
+
infection.time += delta;
|
|
210
240
|
}
|
|
211
241
|
} else {
|
|
212
|
-
|
|
242
|
+
infection.time += delta;
|
|
213
243
|
}
|
|
214
244
|
} else {
|
|
215
|
-
delete
|
|
216
|
-
delete
|
|
245
|
+
delete infection.stage;
|
|
246
|
+
delete infection.time;
|
|
217
247
|
}
|
|
218
248
|
}
|
|
219
249
|
updateInfectionStage(particle, stage) {
|
|
220
|
-
const options = this.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (stage > stagesCount || stage < 0 || particle.infection.stage !== undefined && particle.infection.stage > stage) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
particle.infection.stage = stage;
|
|
229
|
-
particle.infection.time = 0;
|
|
230
|
-
}
|
|
231
|
-
nextInfectionStage(particle) {
|
|
232
|
-
const options = this.container.actualOptions;
|
|
233
|
-
if (!options.infection || !particle.infection) {
|
|
250
|
+
const options = this._container.actualOptions,
|
|
251
|
+
{
|
|
252
|
+
infection
|
|
253
|
+
} = particle;
|
|
254
|
+
if (!options.infection || !infection) {
|
|
234
255
|
return;
|
|
235
256
|
}
|
|
236
257
|
const stagesCount = options.infection.stages.length;
|
|
237
|
-
if (stagesCount
|
|
258
|
+
if (stage > stagesCount || stage < 0 || infection.stage !== undefined && infection.stage > stage) {
|
|
238
259
|
return;
|
|
239
260
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (options.infection.cure) {
|
|
243
|
-
delete particle.infection.stage;
|
|
244
|
-
delete particle.infection.time;
|
|
245
|
-
return;
|
|
246
|
-
} else {
|
|
247
|
-
particle.infection.stage = 0;
|
|
248
|
-
particle.infection.time = 0;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
261
|
+
infection.stage = stage;
|
|
262
|
+
infection.time = 0;
|
|
251
263
|
}
|
|
252
264
|
}
|
|
253
265
|
;// CONCATENATED MODULE: ./dist/browser/InfectionInstance.js
|
|
@@ -255,11 +267,11 @@ class Infecter {
|
|
|
255
267
|
|
|
256
268
|
class InfectionInstance {
|
|
257
269
|
constructor(container) {
|
|
258
|
-
this.
|
|
259
|
-
this.
|
|
270
|
+
this._container = container;
|
|
271
|
+
this._container.infecter = new Infecter(this._container);
|
|
260
272
|
}
|
|
261
273
|
particleFillColor(particle) {
|
|
262
|
-
const options = this.
|
|
274
|
+
const options = this._container.actualOptions;
|
|
263
275
|
if (!particle.infection || !options.infection) {
|
|
264
276
|
return;
|
|
265
277
|
}
|
|
@@ -272,13 +284,12 @@ class InfectionInstance {
|
|
|
272
284
|
return this.particleFillColor(particle);
|
|
273
285
|
}
|
|
274
286
|
particlesSetup() {
|
|
275
|
-
|
|
276
|
-
const options = this.container.actualOptions;
|
|
287
|
+
const options = this._container.actualOptions;
|
|
277
288
|
if (!options.infection) {
|
|
278
289
|
return;
|
|
279
290
|
}
|
|
280
291
|
for (let i = 0; i < options.infection.infections; i++) {
|
|
281
|
-
const notInfected = this.
|
|
292
|
+
const notInfected = this._container.particles.filter(p => {
|
|
282
293
|
const infP = p;
|
|
283
294
|
if (!infP.infection) {
|
|
284
295
|
infP.infection = {};
|
|
@@ -286,7 +297,7 @@ class InfectionInstance {
|
|
|
286
297
|
return infP.infection.stage === undefined;
|
|
287
298
|
});
|
|
288
299
|
const infected = (0,engine_root_window_.itemFromArray)(notInfected);
|
|
289
|
-
|
|
300
|
+
this._container.infecter?.startInfection(infected, 0);
|
|
290
301
|
}
|
|
291
302
|
}
|
|
292
303
|
}
|
|
@@ -299,50 +310,46 @@ class ParticlesInfecter extends engine_root_window_.ParticlesInteractorBase {
|
|
|
299
310
|
clear() {}
|
|
300
311
|
init() {}
|
|
301
312
|
async interact(p1, delta) {
|
|
302
|
-
var _a, _b, _c, _d, _e;
|
|
303
313
|
const infecter = this.container.infecter;
|
|
304
314
|
if (!infecter) {
|
|
305
315
|
return;
|
|
306
316
|
}
|
|
307
317
|
infecter.updateInfection(p1, delta.value);
|
|
308
|
-
if (
|
|
318
|
+
if (p1.infection?.stage === undefined) {
|
|
309
319
|
return;
|
|
310
320
|
}
|
|
311
321
|
const container = this.container,
|
|
312
322
|
options = container.actualOptions,
|
|
313
323
|
infectionOptions = options.infection;
|
|
314
|
-
if (!
|
|
324
|
+
if (!infectionOptions?.enable || infectionOptions.stages.length < 1) {
|
|
315
325
|
return;
|
|
316
326
|
}
|
|
317
327
|
const infectionStage1 = infectionOptions.stages[p1.infection.stage],
|
|
318
328
|
pxRatio = container.retina.pixelRatio,
|
|
319
329
|
radius = p1.getRadius() * 2 + infectionStage1.radius * pxRatio,
|
|
320
330
|
pos = p1.getPosition(),
|
|
321
|
-
infectedStage1 =
|
|
331
|
+
infectedStage1 = infectionStage1.infectedStage ?? p1.infection.stage,
|
|
322
332
|
query = container.particles.quadTree.queryCircle(pos, radius),
|
|
323
333
|
infections = infectionStage1.rate,
|
|
324
334
|
neighbors = query.length;
|
|
325
335
|
for (const p2 of query) {
|
|
326
336
|
const infP2 = p2;
|
|
327
|
-
if (infP2 === p1 || infP2.destroyed || infP2.spawning || !(
|
|
337
|
+
if (infP2 === p1 || infP2.destroyed || infP2.spawning || !(infP2.infection?.stage === undefined || infP2.infection.stage !== p1.infection.stage) || (0,engine_root_window_.getRandom)() >= infections / neighbors) {
|
|
328
338
|
continue;
|
|
329
339
|
}
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
infecter.updateInfectionStage(p1, infectedStage2);
|
|
339
|
-
}
|
|
340
|
+
if (infP2.infection?.stage === undefined) {
|
|
341
|
+
infecter.startInfection(infP2, infectedStage1);
|
|
342
|
+
} else if (infP2.infection.stage < p1.infection.stage) {
|
|
343
|
+
infecter.updateInfectionStage(infP2, infectedStage1);
|
|
344
|
+
} else if (infP2.infection.stage > p1.infection.stage) {
|
|
345
|
+
const infectionStage2 = infectionOptions.stages[infP2.infection.stage];
|
|
346
|
+
const infectedStage2 = infectionStage2?.infectedStage ?? infP2.infection.stage;
|
|
347
|
+
infecter.updateInfectionStage(p1, infectedStage2);
|
|
340
348
|
}
|
|
341
349
|
}
|
|
342
350
|
}
|
|
343
351
|
isEnabled() {
|
|
344
|
-
|
|
345
|
-
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;
|
|
352
|
+
return this.container.actualOptions?.infection?.enable ?? false;
|
|
346
353
|
}
|
|
347
354
|
reset() {}
|
|
348
355
|
}
|
|
@@ -358,24 +365,23 @@ class InfectionPlugin {
|
|
|
358
365
|
return new InfectionInstance(container);
|
|
359
366
|
}
|
|
360
367
|
loadOptions(options, source) {
|
|
361
|
-
if (!this.needsPlugin(source)) {
|
|
368
|
+
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
362
369
|
return;
|
|
363
370
|
}
|
|
364
371
|
let infectionOptions = options.infection;
|
|
365
|
-
if (
|
|
372
|
+
if (infectionOptions?.load === undefined) {
|
|
366
373
|
options.infection = infectionOptions = new Infection();
|
|
367
374
|
}
|
|
368
|
-
infectionOptions.load(source
|
|
375
|
+
infectionOptions.load(source?.infection);
|
|
369
376
|
}
|
|
370
377
|
needsPlugin(options) {
|
|
371
|
-
|
|
372
|
-
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;
|
|
378
|
+
return options?.infection?.enable ?? false;
|
|
373
379
|
}
|
|
374
380
|
}
|
|
375
|
-
async function loadInfectionPlugin(engine) {
|
|
381
|
+
async function loadInfectionPlugin(engine, refresh = true) {
|
|
376
382
|
const plugin = new InfectionPlugin();
|
|
377
|
-
await engine.addPlugin(plugin);
|
|
378
|
-
await engine.addInteractor("particlesInfection", container => new ParticlesInfecter(container));
|
|
383
|
+
await engine.addPlugin(plugin, refresh);
|
|
384
|
+
await engine.addInteractor("particlesInfection", container => new ParticlesInfecter(container), refresh);
|
|
379
385
|
}
|
|
380
386
|
|
|
381
387
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see tsparticles.plugin.infection.min.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var i="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},i={};function n(e){var o=i[e];if(void 0!==o)return o.exports;var
|
|
2
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var i="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},i={};function n(e){var o=i[e];if(void 0!==o)return o.exports;var s=i[e]={exports:{}};return t[e](s,s.exports,n),s.exports}n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{n.r(o),n.d(o,{loadInfectionPlugin:()=>l});var e=n(533);class t{constructor(){this.color=new e.OptionsColor,this.color.value="#ff0000",this.radius=0,this.rate=1}load(t){void 0!==t&&(void 0!==t.color&&(this.color=e.OptionsColor.create(this.color,t.color)),this.duration=t.duration,this.infectedStage=t.infectedStage,void 0!==t.radius&&(this.radius=t.radius),void 0!==t.rate&&(this.rate=t.rate))}}class i{constructor(){this.cure=!1,this.delay=0,this.enable=!1,this.infections=0,this.stages=[]}load(e){void 0!==e&&(void 0!==e.cure&&(this.cure=e.cure),void 0!==e.delay&&(this.delay=e.delay),void 0!==e.enable&&(this.enable=e.enable),void 0!==e.infections&&(this.infections=e.infections),void 0!==e.stages&&(this.stages=e.stages.map((e=>{const i=new t;return i.load(e),i}))))}}class s{constructor(e){this._nextInfectionStage=e=>{const t=this._container.actualOptions.infection,{infection:i}=e;if(!t||!i)return;const n=t.stages.length;if(!(n<=0||void 0===i.stage)&&(i.time=0,n<=++i.stage)){if(t.cure)return delete i.stage,void delete i.time;i.stage=0,i.time=0}},this._container=e}startInfection(e,t){const i=this._container.actualOptions.infection,{infection:n}=e;if(!i||!n)return;t>i.stages.length||t<0||(n.delay=0,n.delayStage=t)}updateInfection(e,t){const i=this._container.actualOptions.infection,{infection:n}=e;if(!i||!n)return;const o=i.stages,s=o.length;if(void 0!==n.delay&&void 0!==n.delayStage){const e=n.delayStage;if(e>s||e<0)return;n.delay>=1e3*i.delay?(n.stage=e,n.time=0,delete n.delay,delete n.delayStage):n.delay+=t}else delete n.delay,delete n.delayStage;if(void 0!==n.stage&&void 0!==n.time){const i=o[n.stage];void 0!==i.duration&&i.duration>=0&&n.time>1e3*i.duration?this._nextInfectionStage(e):n.time+=t}else delete n.stage,delete n.time}updateInfectionStage(e,t){const i=this._container.actualOptions,{infection:n}=e;if(!i.infection||!n)return;t>i.infection.stages.length||t<0||void 0!==n.stage&&n.stage>t||(n.stage=t,n.time=0)}}class a{constructor(e){this._container=e,this._container.infecter=new s(this._container)}particleFillColor(e){const t=this._container.actualOptions;if(!e.infection||!t.infection)return;const i=e.infection.stage,n=t.infection.stages;return void 0!==i?n[i].color:void 0}particleStrokeColor(e){return this.particleFillColor(e)}particlesSetup(){const t=this._container.actualOptions;if(t.infection)for(let i=0;i<t.infection.infections;i++){const t=this._container.particles.filter((e=>{const t=e;return t.infection||(t.infection={}),void 0===t.infection.stage})),i=(0,e.itemFromArray)(t);this._container.infecter?.startInfection(i,0)}}}class r extends e.ParticlesInteractorBase{constructor(e){super(e)}clear(){}init(){}async interact(t,i){const n=this.container.infecter;if(!n)return;if(n.updateInfection(t,i.value),void 0===t.infection?.stage)return;const o=this.container,s=o.actualOptions.infection;if(!s?.enable||s.stages.length<1)return;const a=s.stages[t.infection.stage],r=o.retina.pixelRatio,c=2*t.getRadius()+a.radius*r,l=t.getPosition(),f=a.infectedStage??t.infection.stage,d=o.particles.quadTree.queryCircle(l,c),u=a.rate,g=d.length;for(const i of d){const o=i;if(!(o===t||o.destroyed||o.spawning||void 0!==o.infection?.stage&&o.infection.stage===t.infection.stage||(0,e.getRandom)()>=u/g))if(void 0===o.infection?.stage)n.startInfection(o,f);else if(o.infection.stage<t.infection.stage)n.updateInfectionStage(o,f);else if(o.infection.stage>t.infection.stage){const e=s.stages[o.infection.stage],i=e?.infectedStage??o.infection.stage;n.updateInfectionStage(t,i)}}}isEnabled(){return this.container.actualOptions?.infection?.enable??!1}reset(){}}class c{constructor(){this.id="infection"}getPlugin(e){return new a(e)}loadOptions(e,t){if(!this.needsPlugin(e)&&!this.needsPlugin(t))return;let n=e.infection;void 0===n?.load&&(e.infection=n=new i),n.load(t?.infection)}needsPlugin(e){return e?.infection?.enable??!1}}async function l(e,t=!0){const i=new c;await e.addPlugin(i,t),await e.addInteractor("particlesInfection",(e=>new r(e)),t)}})(),o})()));
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Author : Matteo Bruni
|
|
3
|
-
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
-
* Demo / Generator : https://particles.js.org/
|
|
5
|
-
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
-
* How to use? : Check the GitHub README
|
|
7
|
-
* v3.0.0-alpha.1
|
|
8
|
-
*/
|
|
1
|
+
/*! tsParticles Infection Plugin v3.0.0-beta.1 by Matteo Bruni */
|
package/types/Infecter.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { InfectableContainer, InfectableParticle } from "./Types";
|
|
1
|
+
import type { InfectableContainer, InfectableParticle } from "./Types.js";
|
|
2
2
|
export declare class Infecter {
|
|
3
|
-
private readonly
|
|
3
|
+
private readonly _container;
|
|
4
4
|
constructor(container: InfectableContainer);
|
|
5
5
|
startInfection(particle: InfectableParticle, stage: number): void;
|
|
6
6
|
updateInfection(particle: InfectableParticle, delta: number): void;
|
|
7
7
|
updateInfectionStage(particle: InfectableParticle, stage: number): void;
|
|
8
|
-
private
|
|
8
|
+
private readonly _nextInfectionStage;
|
|
9
9
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { InfectableContainer, InfectableParticle } from "./Types";
|
|
1
|
+
import { type IContainerPlugin, type IOptionsColor, type Particle } from "@tsparticles/engine";
|
|
2
|
+
import type { InfectableContainer, InfectableParticle } from "./Types.js";
|
|
3
3
|
export declare class InfectionInstance implements IContainerPlugin {
|
|
4
|
-
private readonly
|
|
4
|
+
private readonly _container;
|
|
5
5
|
constructor(container: InfectableContainer);
|
|
6
6
|
particleFillColor(particle: InfectableParticle): string | IOptionsColor | undefined;
|
|
7
7
|
particleStrokeColor(particle: Particle): string | IOptionsColor | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
-
import type { IInfection } from "../Interfaces/IInfection";
|
|
3
|
-
import { InfectionStage } from "./InfectionStage";
|
|
2
|
+
import type { IInfection } from "../Interfaces/IInfection.js";
|
|
3
|
+
import { InfectionStage } from "./InfectionStage.js";
|
|
4
4
|
export declare class Infection implements IInfection, IOptionLoader<IInfection> {
|
|
5
5
|
cure: boolean;
|
|
6
6
|
delay: number;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { IInfectionStage } from "../Interfaces/IInfectionStage";
|
|
3
|
-
import { OptionsColor } from "@tsparticles/engine";
|
|
1
|
+
import { type IOptionLoader, OptionsColor, type RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { IInfectionStage } from "../Interfaces/IInfectionStage.js";
|
|
4
3
|
export declare class InfectionStage implements IInfectionStage, IOptionLoader<IInfectionStage> {
|
|
5
4
|
color: OptionsColor;
|
|
6
5
|
duration?: number;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
import type { IDelta } from "@tsparticles/engine";
|
|
1
|
+
import { type IDelta, ParticlesInteractorBase } from "@tsparticles/engine";
|
|
2
|
+
import type { InfectableContainer, InfectableParticle } from "./Types.js";
|
|
4
3
|
export declare class ParticlesInfecter extends ParticlesInteractorBase<InfectableContainer> {
|
|
5
4
|
constructor(container: InfectableContainer);
|
|
6
5
|
clear(): void;
|
package/types/Types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Container, IOptions, IParticle, Options, Particle } from "@tsparticles/engine";
|
|
2
|
-
import type { IInfection } from "./Options/Interfaces/IInfection";
|
|
3
|
-
import type { Infecter } from "./Infecter";
|
|
4
|
-
import type { Infection } from "./Options/Classes/Infection";
|
|
2
|
+
import type { IInfection } from "./Options/Interfaces/IInfection.js";
|
|
3
|
+
import type { Infecter } from "./Infecter.js";
|
|
4
|
+
import type { Infection } from "./Options/Classes/Infection.js";
|
|
5
5
|
export interface IParticleInfection {
|
|
6
6
|
delay?: number;
|
|
7
7
|
delayStage?: number;
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Engine } from "@tsparticles/engine";
|
|
2
|
-
export declare function loadInfectionPlugin(engine: Engine): Promise<void>;
|
|
3
|
-
export * from "./Options/Interfaces/IInfection";
|
|
4
|
-
export * from "./Options/Interfaces/IInfectionStage";
|
|
2
|
+
export declare function loadInfectionPlugin(engine: Engine, refresh?: boolean): Promise<void>;
|
|
3
|
+
export * from "./Options/Interfaces/IInfection.js";
|
|
4
|
+
export * from "./Options/Interfaces/IInfectionStage.js";
|
package/umd/Infecter.js
CHANGED
|
@@ -12,99 +12,97 @@
|
|
|
12
12
|
exports.Infecter = void 0;
|
|
13
13
|
class Infecter {
|
|
14
14
|
constructor(container) {
|
|
15
|
-
this.
|
|
15
|
+
this._nextInfectionStage = (particle) => {
|
|
16
|
+
const infectionOptions = this._container.actualOptions.infection, { infection } = particle;
|
|
17
|
+
if (!infectionOptions || !infection) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const stagesCount = infectionOptions.stages.length;
|
|
21
|
+
if (stagesCount <= 0 || infection.stage === undefined) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
infection.time = 0;
|
|
25
|
+
if (stagesCount <= ++infection.stage) {
|
|
26
|
+
if (infectionOptions.cure) {
|
|
27
|
+
delete infection.stage;
|
|
28
|
+
delete infection.time;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
infection.stage = 0;
|
|
33
|
+
infection.time = 0;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
this._container = container;
|
|
16
38
|
}
|
|
17
39
|
startInfection(particle, stage) {
|
|
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 =
|
|
44
|
+
const stages = infectionOptions.stages, stagesCount = stages.length;
|
|
23
45
|
if (stage > stagesCount || stage < 0) {
|
|
24
46
|
return;
|
|
25
47
|
}
|
|
26
|
-
|
|
27
|
-
|
|
48
|
+
infection.delay = 0;
|
|
49
|
+
infection.delayStage = stage;
|
|
28
50
|
}
|
|
29
51
|
updateInfection(particle, delta) {
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
52
|
+
const infectionOptions = this._container.actualOptions.infection, { infection } = particle;
|
|
53
|
+
if (!infectionOptions || !infection) {
|
|
32
54
|
return;
|
|
33
55
|
}
|
|
34
|
-
const stages =
|
|
35
|
-
if (
|
|
36
|
-
const stage =
|
|
56
|
+
const stages = infectionOptions.stages, stagesCount = stages.length;
|
|
57
|
+
if (infection.delay !== undefined && infection.delayStage !== undefined) {
|
|
58
|
+
const stage = infection.delayStage;
|
|
37
59
|
if (stage > stagesCount || stage < 0) {
|
|
38
60
|
return;
|
|
39
61
|
}
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
delete
|
|
44
|
-
delete
|
|
62
|
+
if (infection.delay >= infectionOptions.delay * 1000) {
|
|
63
|
+
infection.stage = stage;
|
|
64
|
+
infection.time = 0;
|
|
65
|
+
delete infection.delay;
|
|
66
|
+
delete infection.delayStage;
|
|
45
67
|
}
|
|
46
68
|
else {
|
|
47
|
-
|
|
69
|
+
infection.delay += delta;
|
|
48
70
|
}
|
|
49
71
|
}
|
|
50
72
|
else {
|
|
51
|
-
delete
|
|
52
|
-
delete
|
|
73
|
+
delete infection.delay;
|
|
74
|
+
delete infection.delayStage;
|
|
53
75
|
}
|
|
54
|
-
if (
|
|
55
|
-
const infectionStage = stages[
|
|
76
|
+
if (infection.stage !== undefined && infection.time !== undefined) {
|
|
77
|
+
const infectionStage = stages[infection.stage];
|
|
56
78
|
if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
|
|
57
|
-
if (
|
|
58
|
-
this.
|
|
79
|
+
if (infection.time > infectionStage.duration * 1000) {
|
|
80
|
+
this._nextInfectionStage(particle);
|
|
59
81
|
}
|
|
60
82
|
else {
|
|
61
|
-
|
|
83
|
+
infection.time += delta;
|
|
62
84
|
}
|
|
63
85
|
}
|
|
64
86
|
else {
|
|
65
|
-
|
|
87
|
+
infection.time += delta;
|
|
66
88
|
}
|
|
67
89
|
}
|
|
68
90
|
else {
|
|
69
|
-
delete
|
|
70
|
-
delete
|
|
91
|
+
delete infection.stage;
|
|
92
|
+
delete infection.time;
|
|
71
93
|
}
|
|
72
94
|
}
|
|
73
95
|
updateInfectionStage(particle, stage) {
|
|
74
|
-
const options = this.
|
|
75
|
-
if (!options.infection || !
|
|
96
|
+
const options = this._container.actualOptions, { infection } = particle;
|
|
97
|
+
if (!options.infection || !infection) {
|
|
76
98
|
return;
|
|
77
99
|
}
|
|
78
100
|
const stagesCount = options.infection.stages.length;
|
|
79
|
-
if (stage > stagesCount ||
|
|
80
|
-
stage < 0 ||
|
|
81
|
-
(particle.infection.stage !== undefined && particle.infection.stage > stage)) {
|
|
101
|
+
if (stage > stagesCount || stage < 0 || (infection.stage !== undefined && infection.stage > stage)) {
|
|
82
102
|
return;
|
|
83
103
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
nextInfectionStage(particle) {
|
|
88
|
-
const options = this.container.actualOptions;
|
|
89
|
-
if (!options.infection || !particle.infection) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const stagesCount = options.infection.stages.length;
|
|
93
|
-
if (stagesCount <= 0 || particle.infection.stage === undefined) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
particle.infection.time = 0;
|
|
97
|
-
if (stagesCount <= ++particle.infection.stage) {
|
|
98
|
-
if (options.infection.cure) {
|
|
99
|
-
delete particle.infection.stage;
|
|
100
|
-
delete particle.infection.time;
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
particle.infection.stage = 0;
|
|
105
|
-
particle.infection.time = 0;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
104
|
+
infection.stage = stage;
|
|
105
|
+
infection.time = 0;
|
|
108
106
|
}
|
|
109
107
|
}
|
|
110
108
|
exports.Infecter = Infecter;
|
package/umd/InfectionInstance.js
CHANGED
|
@@ -4,21 +4,21 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine", "./Infecter.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.InfectionInstance = void 0;
|
|
13
|
-
const Infecter_1 = require("./Infecter");
|
|
14
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const Infecter_js_1 = require("./Infecter.js");
|
|
15
15
|
class InfectionInstance {
|
|
16
16
|
constructor(container) {
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
17
|
+
this._container = container;
|
|
18
|
+
this._container.infecter = new Infecter_js_1.Infecter(this._container);
|
|
19
19
|
}
|
|
20
20
|
particleFillColor(particle) {
|
|
21
|
-
const options = this.
|
|
21
|
+
const options = this._container.actualOptions;
|
|
22
22
|
if (!particle.infection || !options.infection) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
@@ -29,13 +29,12 @@
|
|
|
29
29
|
return this.particleFillColor(particle);
|
|
30
30
|
}
|
|
31
31
|
particlesSetup() {
|
|
32
|
-
|
|
33
|
-
const options = this.container.actualOptions;
|
|
32
|
+
const options = this._container.actualOptions;
|
|
34
33
|
if (!options.infection) {
|
|
35
34
|
return;
|
|
36
35
|
}
|
|
37
36
|
for (let i = 0; i < options.infection.infections; i++) {
|
|
38
|
-
const notInfected = this.
|
|
37
|
+
const notInfected = this._container.particles.filter((p) => {
|
|
39
38
|
const infP = p;
|
|
40
39
|
if (!infP.infection) {
|
|
41
40
|
infP.infection = {};
|
|
@@ -43,7 +42,7 @@
|
|
|
43
42
|
return infP.infection.stage === undefined;
|
|
44
43
|
});
|
|
45
44
|
const infected = (0, engine_1.itemFromArray)(notInfected);
|
|
46
|
-
|
|
45
|
+
this._container.infecter?.startInfection(infected, 0);
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
}
|