diff --git a/src/game-lib-component-trigger-box-box.js b/src/game-lib-component-trigger-box-box.js index c999894..6d92be7 100644 --- a/src/game-lib-component-trigger-box-box.js +++ b/src/game-lib-component-trigger-box-box.js @@ -7,7 +7,8 @@ GameLib.D3.ComponentTriggerBoxBox = function( entitiesToCheck, onInside, onEnter, - onLeave + onLeave, + onSetParent ) { this.componentId = componentId || GameLib.D3.Tools.RandomId(); this.parentEntity = null; @@ -19,6 +20,7 @@ GameLib.D3.ComponentTriggerBoxBox = function( this.onInside = onInside || null; this.onEnter = onEnter || null; this.onLeave = onLeave || null; + this.onSetParent = onSetParent || null; // runtime code this.entitiesInside = []; @@ -52,23 +54,38 @@ GameLib.D3.ComponentTriggerBoxBox.prototype.onUpdate = function( this.entitiesInside.push(entityToCheck); if(this.onEnter) { - this.onEnter(parentEntity, entityToCheck); + if(this.onEnter(parentEntity, entityToCheck)) { + break; + } } } if(this.onInside) { - this.onInside(parentEntity, entityToCheck); + if(this.onInside(parentEntity, entityToCheck)) { + break; + } } } else if(this.entitiesInside.indexOf(entityToCheck) > -1) { // entity WAS inside the trigger this.entitiesInside.splice(this.entitiesInside.indexOf(entityToCheck), 1); if(this.onLeave) { - this.onLeave(parentEntity, entityToCheck); + if(this.onLeave(parentEntity, entityToCheck)) { + break; + } } } } } +}; + +GameLib.D3.ComponentTriggerBoxBox.prototype.onSetParentEntity = function( + parentScene, + parentEntity +) { + if(this.onSetParent) { + this.onSetParent(parentScene, parentEntity); + } }; \ No newline at end of file diff --git a/src/game-lib-component-trigger-box-sphere.js b/src/game-lib-component-trigger-box-sphere.js index 2f91a2c..e4cfa37 100644 --- a/src/game-lib-component-trigger-box-sphere.js +++ b/src/game-lib-component-trigger-box-sphere.js @@ -7,7 +7,8 @@ GameLib.D3.ComponentTriggerBoxSphere = function( entitiesToCheck, onInside, onEnter, - onLeave + onLeave, + onSetParent ) { this.componentId = componentId || GameLib.D3.Tools.RandomId(); this.parentEntity = null; @@ -19,6 +20,7 @@ GameLib.D3.ComponentTriggerBoxSphere = function( this.onInside = onInside || null; this.onEnter = onEnter || null; this.onLeave = onLeave || null; + this.onSetParent = onSetParent || null; // runtime code this.entitiesInside = []; @@ -79,23 +81,38 @@ GameLib.D3.ComponentTriggerBoxSphere.prototype.onUpdate = function( this.entitiesInside.push(entityToCheck); if(this.onEnter) { - this.onEnter(parentEntity, entityToCheck); + if(this.onEnter(parentEntity, entityToCheck)) { + break; + } } } if(this.onInside) { - this.onInside(parentEntity, entityToCheck); + if(this.onInside(parentEntity, entityToCheck)) { + break; + } } } else if(this.entitiesInside.indexOf(entityToCheck) > -1) { // entity WAS inside the trigger this.entitiesInside.splice(this.entitiesInside.indexOf(entityToCheck), 1); if(this.onLeave) { - this.onLeave(parentEntity, entityToCheck); + if(this.onLeave(parentEntity, entityToCheck)) { + break; + } } } } } +}; + +GameLib.D3.ComponentTriggerBoxSphere.prototype.onSetParentEntity = function( + parentScene, + parentEntity +) { + if(this.onSetParent) { + this.onSetParent(parentScene, parentEntity); + } }; \ No newline at end of file diff --git a/src/game-lib-component-trigger-sphere-sphere.js b/src/game-lib-component-trigger-sphere-sphere.js index 9cc5b97..ac573ee 100644 --- a/src/game-lib-component-trigger-sphere-sphere.js +++ b/src/game-lib-component-trigger-sphere-sphere.js @@ -9,7 +9,8 @@ GameLib.D3.ComponentTriggerSphereSphere = function( entitiesToCheck, onInside, onEnter, - onLeave + onLeave, + onSetParent ) { this.componentId = componentId || GameLib.D3.Tools.RandomId(); this.parentEntity = null; @@ -22,6 +23,7 @@ GameLib.D3.ComponentTriggerSphereSphere = function( this.onInside = onInside || null; this.onEnter = onEnter || null; this.onLeave = onLeave || null; + this.onSetParent = onSetParent || null; // runtime code this.entitiesInside = []; @@ -84,20 +86,35 @@ GameLib.D3.ComponentTriggerSphereSphere.prototype.onUpdate = function( this.entitiesInside.push(entityToCheck); if(this.onEnter) { - this.onEnter(parentEntity, entityToCheck); + if(this.onEnter(parentEntity, entityToCheck)) { + break; + } } } if(this.onInside) { - this.onInside(parentEntity, entityToCheck); + if(this.onInside(parentEntity, entityToCheck)) { + break; + } } } else if(this.entitiesInside.indexOf(entityToCheck) > -1) { // entity WAS inside the trigger this.entitiesInside.splice(this.entitiesInside.indexOf(entityToCheck), 1); if(this.onLeave) { - this.onLeave(parentEntity, entityToCheck); + if(this.onLeave(parentEntity, entityToCheck)) { + break; + } } } } +}; + +GameLib.D3.ComponentTriggerSphereSphere.prototype.onSetParentEntity = function( + parentScene, + parentEntity +) { + if(this.onSetParent) { + this.onSetParent(parentScene, parentEntity); + } }; \ No newline at end of file