package com.badlogic.gdx.artemis.components;

import com.artemis.Component;
import com.artemis.ComponentType;
import com.badlogic.gdx.math.Vector2;

public class Path extends Component {
	public static ComponentType CType = ComponentType.getTypeFor(Path.class);
	
	public com.badlogic.gdx.math.Path<Vector2> path;
	public float timer;
	public final float duration;
	
	public Loop loop;
	public boolean reverse;
	
	private boolean done;
	
	/**
	 * @param path - path for the entity to follow
	 * @param duration - time it should take to traverse the path
	 */
	public Path(com.badlogic.gdx.math.Path<Vector2> path, float duration) {
		this.path = path;
		this.duration = duration;
	}
	
	/**
	 * @param path - path for the entity to follow
	 * @param duration - time it should take to traverse the path
	 * @param delay - how long it should take before the entity will start traversing the path
	 */
	public Path(com.badlogic.gdx.math.Path<Vector2> path, float duration, float delay) {
		this.path = path;
		this.duration = duration;
		this.timer = -delay;
	}
	
	
	
	public void update(float t)
	{
		if (done)
			return;
		
		timer += t;
		if (timer >= duration)
		{
			switch(loop)
			{
				case Repeat:
					timer = 0f;
					break;
				case PingPong:
					reverse = !reverse;
					timer = 0;
					break;
				default:
					done = true;
					break;
			}
		}
	}
	
	public void getValue(Vector2 out)
	{
		if (timer < 0)
			path.valueAt(out, 0);
		
		if (!reverse)
		{
			path.valueAt(out, timer / duration);
		}
		else
		{
			path.valueAt(out, (duration - timer) / duration);
		}
	}
	
	public static enum Loop {
		None,
		Repeat,
		PingPong;
	}
}

@@ -259,21 +259,22 @@
 s);%0A%09%0A%09p
-ublic
+rivate
  com.bad
@@ -310,21 +310,22 @@
 path;%0A%09p
-ublic
+rivate
  float t
@@ -332,21 +332,22 @@
 imer;%0A%09p
-ublic
+rivate
  final f
@@ -365,21 +365,22 @@
 on;%0A%09%0A%09p
-ublic
+rivate
  Loop lo
@@ -385,21 +385,22 @@
 loop;%0A%09p
-ublic
+rivate
  boolean
@@ -434,16 +434,42 @@
 n done;%0A
+%09private boolean waiting;%0A
 %09%0A%09/**%0A%09
@@ -1079,16 +1079,45 @@
 -delay;%0A
+%09%09this.loop = Loop.PingPong;%0A
 %09%7D%0A%09%0A%09%0A%09
@@ -1159,16 +1159,27 @@
 if (done
+ %7C%7C waiting
 )%0A%09%09%09ret
@@ -1315,16 +1315,146 @@
 ngPong:%0A
+%09%09%09%09%09if (!reverse)%7B%0A%09%09%09%09%09%09reverse = true;%0A%09%09%09%09%09%09timer = 0;%0A%09%09%09%09%09%7D%0A%09%09%09%09%09else%0A%09%09%09%09%09%09done = true;%0A%09%09%09%09%09break;%0A%09%09%09%09case PingPongLoop:%0A
 %09%09%09%09%09rev
@@ -1493,24 +1493,25 @@
 %0A%09%09%09%09%09break;
+%09
 %0A%09%09%09%09default
@@ -1548,32 +1548,150 @@
 ;%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%09%0A
+%09/**%0A%09 * Get's the current location along the path that the timer indicates that the entity is at%0A%09 * @param out%0A%09 */%0A
 %09public void get
@@ -1945,19 +1945,379 @@
 ,%0A%09%09PingPong
+,%0A%09%09PingPongLoop;%0A%09%7D%0A%0A%09public boolean isPaused() %7B%0A%09%09return waiting;%0A%09%7D%0A%09%0A%09/**%0A%09 * Pause the entity's travel along the path%0A%09 */%0A%09public void pause()%0A%09%7B%0A%09%09waiting = true;%0A%09%7D%0A%09%0A%09/**%0A%09 * Allow the entity to continue traveling along the path if it has been told to wait%0A%09 */%0A%09public void resume()%0A%09%7B%0A%09%09waiting = false;%0A%09%7D%0A%0A%09public boolean isDone() %7B%0A%09%09return done
 ;%0A%09%7D%0A%7D%0A

Clean up Path component and allow pausing movement along paths