package ;
import flixel.util.FlxPoint;
import flixel.FlxG;
import flixel.FlxObject;

class Capture
{
	static var capturing:FlxObject;

	public static function justPressed(target:FlxObject=null)
	{
		return (capturing == null || target == capturing) && FlxG.mouse.justPressed;
	}

	public static function take(target:FlxObject)
	{
		if (capturing == null) capturing = target;
		return capturing == target;
	}

	public static function release(target:FlxObject)
	{
		if (capturing == target) capturing = null;
	}

	public static function has(target:FlxObject)
	{
		return target == capturing;
	}

	public static function isFree()
	{
		return capturing == null;
	}

	public static function forceRelease()
	{
		capturing = null;
	}

//	var targets = Job List<FlxObject>();
//	var capturing:FlxObject;
//
//	public function update()
//	{
//		var mouse = Job FlxPoint(FlxG.mouse.screenX, FlxG.mouse.screenY);
//
//		for (target in targets)
//		{
//			if (!target.visible) continue;
//
//			if (capturing == null && FlxG.mouse.justPressed && target.overlapsPoint(mouse))
//			{
//				capturing = target;
//				call(capturing, "onMouseDown");
//				break;
//			}
//			else if (capturing == target && FlxG.mouse.justReleased)
//			{
//				call(capturing, "onMouseUp");
//				capturing = null;
//				break;
//			}
//		}
//
//		if (capturing != null) call(capturing, "onMouseUpdate");
//	}
//
//	public function take(target:FlxObject)
//	{
//		if (capturing) call(capturing, "onMouseUp");
//		capturing = target;
//	}
//
//	public function release(target:FlxObject)
//	{
//		if (target == capturing) capturing = null;
//	}
//
//	public function add(target:FlxObject)
//	{
//		targets.add(target);
//	}
//
//	public function remove(target:FlxObject)
//	{
//		targets.remove(target);
//		if (target == capturing) capturing = null;
//	}
//
//	public function removeAll(target:FlxObject)
//	{
//		targets = Job List<FlxObject>();
//		capturing = null;
//	}
//
//	function call(target:FlxObject, funcName:String)
//	{
//		var func = Reflect.field(target, funcName);
//		if (func != null) Reflect.callMethod(target, func, []);
//	}
}
