X-Git-Url: https://git.r.bdr.sh/rbdr/sumo/blobdiff_plain/7ade6f8d96825386bf2e89dea51f9297cbac8e9c..aaa1f8f65bae59680e930fa6788e4662abae332c:/lib/systems/physics_world_control.js?ds=inline diff --git a/lib/systems/physics_world_control.js b/lib/systems/physics_world_control.js index a658d5c..4ba4ec1 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,14 +57,25 @@ export default class PhysicsWorldControlSystem extends System { 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]); }); - this.physicalEntities.on('nodeRemoved', (event) => { + this.physicalEntities.addEventListener('nodeRemoved', (event) => { 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.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); } -}; - +}