]> git.r.bdr.sh - rbdr/sumo/blobdiff - lib/systems/physics_world_control.js
Update dependencies
[rbdr/sumo] / lib / systems / physics_world_control.js
index a658d5cc8cca89e013b4347d485f5507e1bb8e40..4ba4ec1a5ef2a3fa83f905cbcc03693cd1efd046 100644 (file)
@@ -2,6 +2,7 @@ import { System } from '@serpentity/serpentity';
 import { Engine, World } from 'matter-js';
 
 import PhysicalNode from '../nodes/physical';
 import { Engine, World } from 'matter-js';
 
 import PhysicalNode from '../nodes/physical';
+import GrabAreaNode from '../nodes/grab_area';
 
 const internals = {
   kNoEngine: 'No matter js physics engine found. Make sure you set the `engine` key in the config object when initializing.'
 
 const internals = {
   kNoEngine: 'No matter js physics engine found. Make sure you set the `engine` key in the config object when initializing.'
@@ -56,14 +57,25 @@ export default class PhysicsWorldControlSystem extends System {
   added(engine) {
 
     this.physicalEntities = engine.getNodes(PhysicalNode);
   added(engine) {
 
     this.physicalEntities = engine.getNodes(PhysicalNode);
-    this.physicalEntities.on('nodeAdded', (event) => {
+    this.grabAreaEntities = engine.getNodes(GrabAreaNode);
+
+    this.physicalEntities.addEventListener('nodeAdded', (event) => {
 
       World.add(this.engine.world, [event.node.body.body]);
     });
 
       World.add(this.engine.world, [event.node.body.body]);
     });
-    this.physicalEntities.on('nodeRemoved', (event) => {
+    this.physicalEntities.addEventListener('nodeRemoved', (event) => {
 
       World.remove(this.engine.world, [event.node.body.body]);
     });
 
       World.remove(this.engine.world, [event.node.body.body]);
     });
+
+    this.grabAreaEntities.addEventListener('nodeAdded', (event) => {
+
+      World.add(this.engine.world, [event.node.grabArea.area]);
+    });
+    this.grabAreaEntities.addEventListener('nodeRemoved', (event) => {
+
+      World.remove(this.engine.world, [event.node.grabArea.area]);
+    });
   }
 
   /**
   }
 
   /**
@@ -78,6 +90,10 @@ export default class PhysicsWorldControlSystem extends System {
     this.physicalEntities.removeAllListeners('nodeAdded');
     this.physicalEntities.removeAllListeners('nodeRemoved');
     this.physicalEntities = null;
     this.physicalEntities.removeAllListeners('nodeAdded');
     this.physicalEntities.removeAllListeners('nodeRemoved');
     this.physicalEntities = null;
+
+    this.grabAreaEntities.removeAllListeners('nodeAdded');
+    this.grabAreaEntities.removeAllListeners('nodeRemoved');
+    this.grabAreaEntities = null;
   }
 
   /**
   }
 
   /**
@@ -93,6 +109,5 @@ export default class PhysicsWorldControlSystem extends System {
 
     Engine.update(this.engine, currentFrameDuration);
   }
 
     Engine.update(this.engine, currentFrameDuration);
   }
-};
-
+}