//created by keilmillerjr, modified for use with "TurboGrafx-16 Mini" layout


class FadeToGame {
	toGameRunTime = null;
	fromGameRunTime = null;
	shade = null;
	
	constructor() {
		toGameRunTime = 3500
		fromGameRunTime = 200
		
		shade = fe.add_image("white.png", 0, 0, fe.layout.width, fe.layout.height);
		shade.set_rgb(0, 0, 0);
		shade.visible = false;
		shade.zorder = -1;
		
		fe.add_transition_callback(this, "transitions");
	}
	
	function transitions(ttype, var, ttime) {
		switch(ttype) {
			case Transition.ToGame:
				shade.visible = true;
				if (ttime < toGameRunTime) {
					// Fade Out
					shade.alpha = (255 * (ttime - toGameRunTime)) / toGameRunTime;
					return true;
				}
				break;
		}
		return false;
	}
}

fe.plugin["TurboFadeToGame"] <- FadeToGame();