package pathgame.gameplay;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import me.hammerle.snuviengine.api.KeyBinding;
import me.hammerle.snuviengine.api.KeyHandler;
import org.lwjgl.glfw.GLFW;

/**
 * A container for all keys
 *
 * @author julia
 */
public class Keys
{
    public static final KeyBinding UP_KEY = KeyHandler.register(GLFW.GLFW_KEY_W);
    public static final KeyBinding DOWN_KEY = KeyHandler.register(GLFW.GLFW_KEY_S);
    public static final KeyBinding LEFT_KEY = KeyHandler.register(GLFW.GLFW_KEY_A);
    public static final KeyBinding RIGHT_KEY = KeyHandler.register(GLFW.GLFW_KEY_D);
    public static final KeyBinding ZOOM_IN_KEY = KeyHandler.register(GLFW.GLFW_KEY_I);
    public static final KeyBinding ZOOM_OUT_KEY = KeyHandler.register(GLFW.GLFW_KEY_O);
    public static final KeyBinding CONFIRM_KEY = KeyHandler.register(GLFW.GLFW_KEY_ENTER);
    public static final KeyBinding ESCAPE_KEY = KeyHandler.register(GLFW.GLFW_KEY_ESCAPE);
    public static final KeyBinding CAM_UP_KEY = KeyHandler.register(GLFW.GLFW_KEY_UP);
    public static final KeyBinding CAM_DOWN_KEY = KeyHandler.register(GLFW.GLFW_KEY_DOWN);
    public static final KeyBinding CAM_LEFT_KEY = KeyHandler.register(GLFW.GLFW_KEY_LEFT);
    public static final KeyBinding CAM_RIGHT_KEY = KeyHandler.register(GLFW.GLFW_KEY_RIGHT);
    public static final KeyBinding TEST_KEY = KeyHandler.register(GLFW.GLFW_KEY_T);
    public static final KeyBinding OVERLAY_KEY = KeyHandler.register(GLFW.GLFW_KEY_TAB);
    public static final KeyBinding BOAT_KEY = KeyHandler.register(GLFW.GLFW_KEY_E);

    /**
     * An array of all rebindable keys
     */
    public static final KeyBinding[] KEYS = new KeyBinding[]
    {
        UP_KEY, DOWN_KEY, LEFT_KEY, RIGHT_KEY, ZOOM_IN_KEY, ZOOM_OUT_KEY,
        CAM_UP_KEY, CAM_DOWN_KEY, CAM_LEFT_KEY,
        CAM_RIGHT_KEY, OVERLAY_KEY, BOAT_KEY
    };

    /**
     * An array of the names of all rebindable keys
     */
    public static final String[] KEYNAMES =
    {
        "Up Key", "Down Key", "Left Key", "Right Key", "Zoom In Key",
        "Zoom Out Key", "Cam Up Key", "Cam Down Key", "Cam Left Key",
        "Cam Right Key", "Overlay Key", "Boat Key"
    };

    static
    {
        File f = new File("resources/config.bin");
        if(f.exists())
        {
            try(DataInputStream reader = new DataInputStream(new FileInputStream(f)))
            {
                for(int i = 0; i < KEYS.length; ++i)
                {
                    KeyHandler.rebind(KEYS[i], reader.readInt());
                }
            }
            catch(IOException ex)
            {
            }
        }
    }
}
