package me.hammerle.supersnuvi.tiles;

import me.hammerle.supersnuvi.javafx.Image;
import me.hammerle.supersnuvi.entity.Entity;
import me.hammerle.supersnuvi.util.CollisionBox;
import me.hammerle.supersnuvi.util.Face;

public abstract class Tile 
{
    private CollisionBox movementCollision;
    private CollisionBox collisionBox;
    
    public Tile()
    {
        movementCollision = null;
        collisionBox = null;
    }
    
    public abstract Image getImage(int x, int y);
    
    /** Sets the collision box for movement
     *
     * @param cb a collision box
     * @return the tile which the change was applied to
     */
    public Tile setMovementBox(CollisionBox cb)
    {
        if(cb == CollisionBox.NULL_BOX)
        {
            this.movementCollision = null;
        }
        else
        {
            this.movementCollision = cb.copy();
        }
        return this;
    }
    
    /** Sets the collision box for normal collision
     *
     * @param cb a collision box
     * @return the tile which the change was applied to
     */
    public Tile setCollisionBox(CollisionBox cb)
    {
        if(cb == CollisionBox.NULL_BOX)
        {
            this.collisionBox = null;
        }
        else
        {
            this.collisionBox = cb.copy();
        }
        return this;
    }
    
    /** Sets the default collision box for movement and for collision
     *
     * @return the tile which the change was applied to
     */
    public Tile setDefaultCollisionBox()
    {
        this.movementCollision = CollisionBox.DEFAULT_BOX.copy();
        this.collisionBox = CollisionBox.DEFAULT_BOX.copy();
        return this;
    }
    
    public CollisionBox getCollisionBox(int x, int y)
    {
        if(collisionBox != null)
        {
            return collisionBox;
        }
        return CollisionBox.NULL_BOX.reset();
    }
    
    public CollisionBox getMovementBox(int x, int y)
    {
        if(movementCollision != null)
        {
            return movementCollision;
        }
        return CollisionBox.NULL_BOX.reset();
    }
    
    public void onEntityCollide(Entity ent, int x, int y, Face face)
    {
        
    }
    
    public void tick()
    {
    }
    
    public long getKey(int x, int y)
    {
        return x | (((long) y) << 32);
    }
    
    public void reset()
    {
    }
    
    public double getRenderOffsetX()
    {
        return 0;
    }
    
    public double getRenderOffsetY()
    {
        return 0;
    }
}
