X-Git-Url: https://git.r.bdr.sh/rbdr/sumo/blobdiff_plain/7ade6f8d96825386bf2e89dea51f9297cbac8e9c..2bb8e347ed38948e8a65a479d3c1f64b7f7a5d9b:/lib/systems/physics_world_control.js diff --git a/lib/systems/physics_world_control.js b/lib/systems/physics_world_control.js index a658d5c..370701e 100644 --- a/lib/systems/physics_world_control.js +++ b/lib/systems/physics_world_control.js @@ -2,6 +2,7 @@ import { System } from '@serpentity/serpentity'; 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.' @@ -56,6 +57,8 @@ export default class PhysicsWorldControlSystem extends System { added(engine) { this.physicalEntities = engine.getNodes(PhysicalNode); + this.grabAreaEntities = engine.getNodes(GrabAreaNode); + this.physicalEntities.on('nodeAdded', (event) => { World.add(this.engine.world, [event.node.body.body]); @@ -64,6 +67,15 @@ export default class PhysicsWorldControlSystem extends System { World.remove(this.engine.world, [event.node.body.body]); }); + + this.grabAreaEntities.on('nodeAdded', (event) => { + + World.add(this.engine.world, [event.node.grabArea.area]); + }); + this.grabAreaEntities.on('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.grabAreaEntities.removeAllListeners('nodeAdded'); + this.grabAreaEntities.removeAllListeners('nodeRemoved'); + this.grabAreaEntities = null; } /** @@ -95,4 +111,3 @@ export default class PhysicsWorldControlSystem extends System { } }; -