package {
	import com.netgrind.core.Scheduler;
	import adobe.utils.CustomActions;
	import com.netgrind.core.Mouse;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.system.fscommand;
	import flash.ui.Keyboard;
	import nape.geom.Vec2;
	import com.netgrind.core.Key;
	
	/**
	 * ...
	 * @author netgrind
	 */
	public class Main extends Sprite {
		
		private static var _debug:Boolean;
		public static var debugLayer:Sprite;
		public function Main():void {
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			Mouse.init(stage);
			Key.init(stage);
			Scheduler.init(stage);
			
			debugLayer = new Sprite();
			
			//DEBUG STUFF, REMOVE IN FINAL BUILD
			new ContextMenu(stage);
			//END DEBUG STUFF
			
			addChild(new Level);
			
			//addChild(new HUDTarget());
			
			addChild(debugLayer);
			_debug = false;
			Key.bindFunctionToKeyPress(toggleDebug, Keyboard.O);
			Key.bindFunctionToKeyPress(quit, Keyboard.ESCAPE);
		}
		
		public function quit():void {
			fscommand("quit");
		}
		
		private function toggleDebug():void {
			debug = !debug;
		}
		
		static public function get debug():Boolean {
			return _debug;
		}
		
		static public function set debug(value:Boolean):void {
			_debug = value;
			debugLayer.visible = value;
			for (var i:int = 0; i < Poly.all.length; i++) {
				Poly.all[i].draw();
			}
		}
		
	}
	
}