package hud;

import java.awt.Color;
import java.awt.Graphics2D;

import _texture.loader.Textures;
import engine.Game;
import engine.Game.STATE;
import engine.Handler;
import fonts.fonts;
import interfaces.Colors;

/*  ------------- Nihilne ------------
    * Created by Mitch Weaver - 2016 *
      ~~~~ All Rights Reserved ~~~~ */

public class Clock {

	public static int width = 140, height = 140, day = 1, time;
	private static int arrowWidth = 11, arrowHeight = 46;
	public static TIME clock;
	
	public static final int SECOND = 60, MINUTE = SECOND*60, DAWN_DURATION = 1250, DAY_DURATION = 9600, DUSK_DURATION = 3350, NIGHT_DURATION = 7400, FULL_DAY = (DAWN_DURATION + DAY_DURATION + DUSK_DURATION + NIGHT_DURATION);
	
	public static final int DAWN = 0, DAY = 1250, DUSK = 10850, NIGHT = 14200;
	
	public static void init(){ time = DAY; clock = TIME.DAY; }
	
	public enum TIME { DAWN, DAY, DUSK, NIGHT; }

	public static void tick() {
		if (Game.state == STATE.GAME) {
			time++;
			if (time < DAY) clock = TIME.DAWN;
			else if (time > DAY && time < DUSK) clock = TIME.DAY;
			else if (time > DUSK && time < NIGHT) clock = TIME.DUSK;
			else if (time > NIGHT) clock = TIME.NIGHT;
			
				 if(Game.alwaysDawn)  clock = TIME.DAWN;
			else if(Game.alwaysDay)   clock = TIME.DAY;
			else if(Game.alwaysDusk)  clock = TIME.DUSK;
			else if(Game.alwaysNight) clock = TIME.NIGHT;
				
			if (time > FULL_DAY) {
				time = 0;
				day++;
				Handler.getMapImage(); 
				System.gc();
				//save
			}
		}
	}

	public static void render(Graphics2D g2d) {
		g2d.drawImage(Textures.hudSheet[1], 0, 0, null);

		if (Game.drawCurrentTime) {
			g2d.setFont(fonts.fallbackFont);
			g2d.setColor(Color.orange);
			g2d.drawString(clock.toString(), 52, 160);
		}

		Graphics2D arrowg2d = (Graphics2D) g2d.create();

		arrowg2d.rotate(Math.toRadians(time / 60), width / 2, height / 2);

		arrowg2d.drawImage(Textures.hudSheet[2], width / 2 - arrowWidth / 2 - 1, (int) (height / 2 - arrowHeight / 1.3), null);

		g2d.setColor(Colors.offWhite);
		g2d.setFont(fonts.Gregorian32Bold);
		if (day < 100) g2d.drawString("Day " + Integer.toString(day), 31, 81);
		else g2d.drawString("Day " + Integer.toString(day), 14, 81);
	}

}
