package depart.commun.monde2d;

import ca.ntro.app.Ntro;
import ca.ntro.app.fx.controls.World2dMouseEventFx;
import ca.ntro.app.world2d.World2dFx;
import depart.frontal.evenements.EvtChangerCurseur;
import javafx.scene.Cursor;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;

public class MondeDepart2d extends World2dFx {
	
	private Balle2d balleAgrippee;
	
	public MondeDepart2d() {
		super();

		addObject2d("balle",   10, new Balle2d(this));
		addObject2d("terrain", 1, new Terrain2dDepart());
	}

	@Override
	protected void onMouseEventNotConsumed(World2dMouseEventFx mouseEvent) {
		if(balleAgrippee != null
				&& mouseEvent.mouseEventFx().getEventType().equals(MouseEvent.MOUSE_DRAGGED)) {
			
			balleAgrippee.suivreSouris(mouseEvent.worldX(),
					                  mouseEvent.worldY());

		} else if(balleAgrippee != null
				    && mouseEvent.mouseEventFx().getEventType().equals(MouseEvent.MOUSE_RELEASED) 
				    && mouseEvent.mouseEventFx().getButton().equals(MouseButton.PRIMARY)) {
			
			balleAgrippee.relacher();
			balleAgrippee = null;

			Ntro.newEvent(EvtChangerCurseur.class)
			    .setCurseur(null)
			    .trigger();
		}
		
	}

	public void agripperBalle(Balle2d balleAgrippee) {
		this.balleAgrippee = balleAgrippee;
	}

}
