UNPKG

2.55 kBJavaScriptView Raw
1(function (factory) {
2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
5 }
6 else if (typeof define === "function" && define.amd) {
7 define(["require", "exports"], factory);
8 }
9})(function (require, exports) {
10 "use strict";
11 Object.defineProperty(exports, "__esModule", { value: true });
12 exports.InteractionManager = void 0;
13 class InteractionManager {
14 constructor(engine, container) {
15 this.container = container;
16 this._engine = engine;
17 this._interactors = engine.plugins.getInteractors(this.container, true);
18 this._externalInteractors = [];
19 this._particleInteractors = [];
20 }
21 async externalInteract(delta) {
22 for (const interactor of this._externalInteractors) {
23 interactor.isEnabled() && (await interactor.interact(delta));
24 }
25 }
26 handleClickMode(mode) {
27 for (const interactor of this._externalInteractors) {
28 interactor.handleClickMode && interactor.handleClickMode(mode);
29 }
30 }
31 init() {
32 this._externalInteractors = [];
33 this._particleInteractors = [];
34 for (const interactor of this._interactors) {
35 switch (interactor.type) {
36 case "external":
37 this._externalInteractors.push(interactor);
38 break;
39 case "particles":
40 this._particleInteractors.push(interactor);
41 break;
42 }
43 interactor.init();
44 }
45 }
46 async particlesInteract(particle, delta) {
47 for (const interactor of this._externalInteractors) {
48 interactor.clear(particle, delta);
49 }
50 for (const interactor of this._particleInteractors) {
51 interactor.isEnabled(particle) && (await interactor.interact(particle, delta));
52 }
53 }
54 async reset(particle) {
55 for (const interactor of this._externalInteractors) {
56 interactor.isEnabled() && interactor.reset(particle);
57 }
58 for (const interactor of this._particleInteractors) {
59 interactor.isEnabled(particle) && interactor.reset(particle);
60 }
61 }
62 }
63 exports.InteractionManager = InteractionManager;
64});