package me.hammerle.supersnuvi; import me.hammerle.snuviengine.api.KeyBinding; import me.hammerle.snuviengine.api.KeyHandler; import me.hammerle.supersnuvi.savegame.SimpleConfig; import static org.lwjgl.glfw.GLFW.*; public class Keys { public final static KeyBinding UP = KeyHandler.register(GLFW_KEY_UP); public final static KeyBinding DOWN = KeyHandler.register(GLFW_KEY_DOWN); public final static KeyBinding LEFT = KeyHandler.register(GLFW_KEY_LEFT); public final static KeyBinding RIGHT = KeyHandler.register(GLFW_KEY_RIGHT); public final static KeyBinding JUMP = KeyHandler.register(GLFW_KEY_SPACE); public final static KeyBinding RUN = KeyHandler.register(GLFW_KEY_LEFT_SHIFT); public final static KeyBinding ESCAPE = KeyHandler.register(GLFW_KEY_ESCAPE); public final static KeyBinding ENTER = KeyHandler.register(GLFW_KEY_ENTER); public final static KeyBinding TEST = KeyHandler.register(GLFW_KEY_T); private final static KeyBinding[] KEYS = { UP, DOWN, LEFT, RIGHT, JUMP, RUN, ESCAPE, ENTER, TEST }; public static void rebind(KeyBinding binding) { KeyHandler.rebind(binding); } public static int getAmount() { return KEYS.length; } public static KeyBinding get(int index) { return KEYS[index]; } public static void read(SimpleConfig config) { KeyHandler.rebind(UP, config.getInt("key.up", GLFW_KEY_UP)); KeyHandler.rebind(DOWN, config.getInt("key.down", GLFW_KEY_DOWN)); KeyHandler.rebind(LEFT, config.getInt("key.left", GLFW_KEY_LEFT)); KeyHandler.rebind(RIGHT, config.getInt("key.right", GLFW_KEY_RIGHT)); KeyHandler.rebind(JUMP, config.getInt("key.jump", GLFW_KEY_SPACE)); KeyHandler.rebind(RUN, config.getInt("key.run", GLFW_KEY_LEFT_SHIFT)); KeyHandler.rebind(ESCAPE, config.getInt("key.escape", GLFW_KEY_ESCAPE)); KeyHandler.rebind(ENTER, config.getInt("key.enter", GLFW_KEY_ENTER)); } public static void write(SimpleConfig config) { config.set("key.up", UP.getKey()); config.set("key.down", DOWN.getKey()); config.set("key.left", LEFT.getKey()); config.set("key.right", RIGHT.getKey()); config.set("key.jump", JUMP.getKey()); config.set("key.run", RUN.getKey()); config.set("key.escape", ESCAPE.getKey()); config.set("key.enter", ENTER.getKey()); } }