package net.mgsx.game.examples.platformer.tasks;

import net.mgsx.game.examples.platformer.physics.PlayerPhysicSensor;
import net.mgsx.game.plugins.btree.annotations.TaskAlias;

@TaskAlias("playerSensor")
public class PlayerSensorTask extends ConditionTask
{
	@Override
	public void start() {
		// ensure entity has player physic sensor
		// TODO maybe check contact list for init in/out ?
		if(!PlayerPhysicSensor.components.has(getEntity())){
			getEntity().add(getEngine().createComponent(PlayerPhysicSensor.class));
		}
	}
	
	@Override
	public boolean match() {
		PlayerPhysicSensor sensor = PlayerPhysicSensor.components.get(getEntity());
		if(sensor != null){
			return sensor.inside;
		}
		return false;
	}
	

}

@@ -112,16 +112,79 @@
 Sensor;%0A
+import net.mgsx.game.plugins.btree.BTreePlugin.EntityLeafTask;%0A
 import n
@@ -303,17 +303,18 @@
 nds 
-Condition
+EntityLeaf
 Task
@@ -451,64 +451,8 @@
 t ?%0A
-%09%09if(!PlayerPhysicSensor.components.has(getEntity()))%7B%0A%09
 %09%09ge
@@ -521,20 +521,16 @@
 lass));%0A
-%09%09%7D%0A
 %09%7D%0A%09%0A%09@O
@@ -549,21 +549,53 @@
 lic 
-boolean match
+com.badlogic.gdx.ai.btree.Task.Status execute
 () %7B
@@ -696,54 +696,209 @@
 null
-)%7B%0A%09%09%09return sensor.inside;%0A%09%09%7D%0A%09%09return false
+ && sensor.inside)%7B%0A%09%09%09sensor.inside = false;%0A%09%09%09return Status.SUCCEEDED;%0A%09%09%7D%0A%09%09return Status.RUNNING;%0A%09%7D%0A%09%0A%09@Override%0A%09public void end() %7B%0A%09%09getEntity().remove(PlayerPhysicSensor.class);%0A%09%09super.end()
 ;%0A%09%7D

fix player sensor