package {
	import adobe.utils.CustomActions;
	import com.greensock.easing.Linear;
	import com.greensock.TweenLite;
	import com.netgrind.core.Scheduler;
	import com.netgrind.core.UtilsArt;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import com.netgrind.core.Utils;
	import flash.geom.Point;
	/**
	 * ...
	 * @author netgrind
	 */
	public class Character extends Sprite {
		
		public static var all:Vector.<Character> = new Vector.<Character>();
		
		public var faceArt:FaceSprite;
		public var charArt:Sprite;
		public var charName:String = "bubblegum";
		public var color:uint = 0x99ff33;
		public var inCar:Boolean = false;
		
		public function Character(num:int) {
			super();
			all.push(this);
			charArt = UtilsArt.makeRectangle(50, 50, color,0 );
			faceArt = CharacterManager.getFace(num);
			addChild(charArt);
			addChild(faceArt);
			faceArt.alpha = 0;
		}
		
		public function showFace():void {
			faceArt.alpha = 1;
			charArt.alpha = 0;
		}
		public function showChar():void {
			faceArt.alpha = 0;
			charArt.alpha = 1;
		}
		
		public function addToWaypoint(way:Waypoint):void {
			way.addChild(this);
			x = 0;
			y = 0;
		}
		
		public function moveToMirror(mirror:Mirror):void {
			mirror.addChar(Character.all.indexOf(this));		
		}
		public function removeFromMirror(mirror:Mirror):void {
			mirror.removeChar(Character.all.indexOf(this));
		}
		
		public function addToDialog(text:TextWindow):void {
			var pos:Point = (parent==null)?text.charTarget:parent.localToGlobal(new Point(x,y));
			Utils.removeChild(this,false);
			text.addChild(this);
			x = text.charTarget.x;
			y = text.charTarget.y;
			pos = parent.globalToLocal(pos);
			//TweenLite.from(this, 1, {x:pos.x,y:pos.y} );
			TweenLite.to(faceArt, 1, {alpha:1} );
			TweenLite.to(charArt, 1, {alpha:0} );
		}
		
	}
	
}