package com.mygdx.game.Character;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.mygdx.game.Restrictions;

import static com.mygdx.game.Main.cam;

public class Mouse implements Restrictions {
    Texture crosshair = new Texture("core/assets/crosshair.png");


    public void selectedTile(SpriteBatch batch){
        Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0);
        cam.unproject(mousePos);
        int x = getSelectedX(mousePos);
        int y = getSelectedY(mousePos);
        batch.draw(crosshair, x, y);
    }

    public int getSelectedX(Vector3 mousePos) {
        return ((int)(mousePos.x)>>4)<<4;
    }

    public int getSelectedY(Vector3 mousePos) {
        return ((int)(mousePos.y)>>4)<<4;
    }

    public int getTileX(OrthographicCamera cam){
        Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0);
        cam.unproject(mousePos);
        return (getSelectedX(mousePos) + Player.getX()>>1)/TILE_SIZE;
    }

    public int getTileY(OrthographicCamera cam){
        Vector3 mousePos = new Vector3( Gdx.input.getX(), Gdx.input.getY(),0);
        cam.unproject(mousePos);
        return (getSelectedY(mousePos) + Player.getY()>>1)/TILE_SIZE;
    }


    public void render(SpriteBatch batch) {
        selectedTile(batch);
        //System.out.println("X = " + getTileX(cam) + " Y = "+ getTileY(cam));
    }
}
