//===================================================================
// Font for Kaei... :DDDD
//===================================================================
//-------------------------------------------------------------------
// Image directory(ies)
//-------------------------------------------------------------------

/** directory */
let dirImage = GetCurrentScriptDirectory() ~ "Image\";

/** Font Image */
let imgFont =	dirImage ~ "Font.png";

/** Load font graphic */
LoadGraphic( imgFont );

//-------------------------------------------------------------------
// Font variables
//-------------------------------------------------------------------

/** New text color */
let TColor = [ 255, 255, 255, 255, 255, 255 ];

//-------------------------------------------------------------------
// Font functions
//-------------------------------------------------------------------

/**
*	Set the font color
*	@param Red1	( red RGB )
*	@param Green1		( green RBG )
*	@param Blue1	( blue RGB )
*	@param Red2		( red RGB )
*	@param Green2		( green RGB )
*	@param Blue2	( blue RGB )
*/
function TexTextColor( let Red1, let Green1, let Blue1, let Red2, let Green2, let Blue2 ){
		TColor = [ Red1, Green1, Blue1, Red2, Green2, Blue2 ];
}

/**
*	Draw the new text
*	@param Text		( text to draw )
*	@param X	( X Coordinate )
*	@param Y	( Y Coordinate )
*	@param Size		( Font size )
*	@param Layer		( Font layer )
*	@param Alpha	( alpha of the font )
*/
task DrawTexText( let Text, let X, let Y, let Size, let Layer, let Alpha ){
	
	/** Text Variables */
	let objFont = Obj_Create( OBJ_EFFECT );
	let i = 0;
	let _X = 0;
	let _Y = 0;
	let sstring = [];

	/** Position and stuff */
	Obj_SetPosition( objFont, X, Y - 8 );
	Obj_SetSpeed( objFont, 0 );

	/** Effect data */
	ObjEffect_SetAngle( objFont, 0, 0, 0 );
	ObjEffect_SetTexture( objFont, imgFont );
	ObjEffect_SetPrimitiveType( objFont, PRIMITIVE_TRIANGLESTRIP );
	ObjEffect_SetLayer( objFont, Layer );
	ObjEffect_CreateVertex( objFont, length( Text ) * 6 );
	ObjEffect_SetRenderState( objFont, ALPHA );
	ObjEffect_SetScale( objFont, Size, Size );

	/** More variables */
	let Char = 0;
	let CharSpace = 0;
	let LastCharSpace = 0;
	ascent( i in 0 .. length( Text ) ){
		Char = ToNumber( Text[ i ] ) * 32;
		_X += LastCharSpace / 2 + CharSpace / 2;

		ObjEffect_SetVertexXY( objFont, ( i * 6 ), _X, 0 );
		ObjEffect_SetVertexXY( objFont, ( i * 6 ) + 1, _X, 0 );
		ObjEffect_SetVertexXY( objFont, ( i * 6 ) + 2, _X + 32, 0 );
		ObjEffect_SetVertexXY( objFont, ( i * 6 ) + 3, _X, 32 );
		ObjEffect_SetVertexXY( objFont, ( i * 6 ) + 4, _X + 32, 32 );
		ObjEffect_SetVertexXY( objFont, ( i * 6 ) + 5, _X + 32, 32 );

		ObjEffect_SetVertexUV( objFont, ( i * 6 ), Char, 0 );
		ObjEffect_SetVertexUV( objFont, ( i * 6 ) + 1, Char, 0 );
		ObjEffect_SetVertexUV( objFont, ( i * 6 ) + 2, Char + 32, 0 );
		ObjEffect_SetVertexUV( objFont, ( i * 6 ) + 3, Char, 32 );
		ObjEffect_SetVertexUV( objFont, ( i * 6 ) + 4, Char + 32, 32 );
		ObjEffect_SetVertexUV( objFont, ( i * 6 ) + 5, Char + 32, 32 );

		ObjEffect_SetVertexColor( objFont, ( i * 6 ), Alpha, TColor[ 0 ], TColor[ 1 ], TColor[ 2 ] );
		ObjEffect_SetVertexColor( objFont, ( i * 6 ) + 1, Alpha, TColor[ 0 ], TColor[ 1 ], TColor[ 2 ] );
		ObjEffect_SetVertexColor( objFont, ( i * 6 ) + 2, Alpha, TColor[ 0 ], TColor[ 1 ], TColor[ 2 ] );
		ObjEffect_SetVertexColor( objFont, ( i * 6 ) + 3, Alpha, TColor[ 3 ], TColor[ 4 ], TColor[ 5 ] );
		ObjEffect_SetVertexColor( objFont, ( i * 6 ) + 4, Alpha, TColor[ 3 ], TColor[ 4 ], TColor[ 5 ] );
		ObjEffect_SetVertexColor( objFont, ( i * 6 ) + 5, Alpha, TColor[ 3 ], TColor[ 4 ], TColor[ 5 ] );

		LastCharSpace = CharSpace;
	}

	/** End of effect objs */
	loop( 2 ){ yield; }
	Obj_Delete( objFont );

	/** Numbers and stuff ;_; 
	*   by Azure yay~!
	*/
	function ToNumber(character){

	//ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,!?()'"-~


		let ret=0;
		alternative(character)
			case('A') {ret=0;CharSpace=20;} case('B') {ret=1;CharSpace=20;} case('C') {ret=2;CharSpace=20;} case('D') {ret=3;CharSpace=20;}
			case('E') {ret=4;CharSpace=20;} case('F') {ret=5;CharSpace=20;} case('G') {ret=6;CharSpace=20;} case('H') {ret=7;CharSpace=20;}
			case('I') {ret=8;CharSpace=14;} case('J') {ret=9;CharSpace=20;} case('K') {ret=10;CharSpace=20;} case('L') {ret=11;CharSpace=20;}
			case('M') {ret=12;CharSpace=20;} case('N') {ret=13;CharSpace=20;} case('O') {ret=14;CharSpace=20;} case('P') {ret=15;CharSpace=20;}
			case('Q') {ret=16;CharSpace=20;} case('R') {ret=17;CharSpace=20;} case('S') {ret=18;CharSpace=20;} case('T') {ret=19;CharSpace=16;}
			case('U') {ret=20;CharSpace=20;} case('V') {ret=21;CharSpace=20;} case('W') {ret=22;CharSpace=20;} case('X') {ret=23;CharSpace=20;}
			case('Y') {ret=24;CharSpace=20;} case('Z') {ret=25;CharSpace=20;}

			case('a') {ret=26;CharSpace=20;} case('b') {ret=27;CharSpace=20;} case('c') {ret=28;CharSpace=18;} case('d') {ret=29;CharSpace=20;}
			case('e') {ret=30;CharSpace=20;} case('f') {ret=31;CharSpace=14;} case('g') {ret=32;CharSpace=20;} case('h') {ret=33;CharSpace=20;}
			case('i') {ret=34;CharSpace=12;} case('j') {ret=35;CharSpace=14;} case('k') {ret=36;CharSpace=20;} case('l') {ret=37;CharSpace=12;}
			case('m') {ret=38;CharSpace=20;} case('n') {ret=39;CharSpace=20;} case('o') {ret=40;CharSpace=20;} case('p') {ret=41;CharSpace=20;}
			case('q') {ret=42;CharSpace=20;} case('r') {ret=43;CharSpace=20;} case('s') {ret=44;CharSpace=20;} case('t') {ret=45;CharSpace=12;}
			case('u') {ret=46;CharSpace=20;} case('v') {ret=47;CharSpace=20;} case('w') {ret=48;CharSpace=20;} case('x') {ret=49;CharSpace=20;}
			case('y') {ret=50;CharSpace=16;} case('z') {ret=51;CharSpace=20;}
			
			case('0') {ret=52;CharSpace=20;} case('1') {ret=53;CharSpace=16;} case('2') {ret=54;CharSpace=20;} case('3') {ret=55;CharSpace=24;}
			case('4') {ret=56;CharSpace=20;} case('5') {ret=57;CharSpace=20;} case('6') {ret=58;CharSpace=20;} case('7') {ret=59;CharSpace=20;}
			case('8') {ret=60;CharSpace=20;} case('9') {ret=61;CharSpace=20;} 

			case('.') {ret=62;CharSpace=10;} case(',') {ret=63;CharSpace=10;} case('!') {ret=64;CharSpace=12;} case('?') {ret=65;CharSpace=18;} 
			case('(') {ret=66;CharSpace=14;} case(')') {ret=67;CharSpace=14;} case('\') {ret=68;CharSpace=18;} case('/') {ret=69;CharSpace=14;} 
			case('-') {ret=70;CharSpace=24;} case('~') {ret=71;CharSpace=20;} case('+') {ret=72;CharSpace=24;}
			
			others {ret=-1;CharSpace=15;}

		
		return ret;
	}
}
