Keys.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package me.hammerle.supersnuvi;
  2. import me.hammerle.snuviengine.api.KeyBinding;
  3. import me.hammerle.snuviengine.api.KeyHandler;
  4. import me.hammerle.supersnuvi.savegame.SimpleConfig;
  5. import static org.lwjgl.glfw.GLFW.*;
  6. public class Keys
  7. {
  8. public final static KeyBinding UP = KeyHandler.register(GLFW_KEY_UP);
  9. public final static KeyBinding DOWN = KeyHandler.register(GLFW_KEY_DOWN);
  10. public final static KeyBinding LEFT = KeyHandler.register(GLFW_KEY_LEFT);
  11. public final static KeyBinding RIGHT = KeyHandler.register(GLFW_KEY_RIGHT);
  12. public final static KeyBinding JUMP = KeyHandler.register(GLFW_KEY_SPACE);
  13. public final static KeyBinding RUN = KeyHandler.register(GLFW_KEY_LEFT_SHIFT);
  14. public final static KeyBinding ESCAPE = KeyHandler.register(GLFW_KEY_ESCAPE);
  15. public final static KeyBinding ENTER = KeyHandler.register(GLFW_KEY_ENTER);
  16. public final static KeyBinding TEST = KeyHandler.register(GLFW_KEY_T);
  17. private final static KeyBinding[] KEYS =
  18. {
  19. UP, DOWN, LEFT, RIGHT,
  20. JUMP, RUN, ESCAPE, ENTER, TEST
  21. };
  22. public static void rebind(KeyBinding binding)
  23. {
  24. KeyHandler.rebind(binding);
  25. }
  26. public static int getAmount()
  27. {
  28. return KEYS.length;
  29. }
  30. public static KeyBinding get(int index)
  31. {
  32. return KEYS[index];
  33. }
  34. public static void read(SimpleConfig config)
  35. {
  36. KeyHandler.rebind(UP, config.getInt("key.up", GLFW_KEY_UP));
  37. KeyHandler.rebind(DOWN, config.getInt("key.down", GLFW_KEY_DOWN));
  38. KeyHandler.rebind(LEFT, config.getInt("key.left", GLFW_KEY_LEFT));
  39. KeyHandler.rebind(RIGHT, config.getInt("key.right", GLFW_KEY_RIGHT));
  40. KeyHandler.rebind(JUMP, config.getInt("key.jump", GLFW_KEY_SPACE));
  41. KeyHandler.rebind(RUN, config.getInt("key.run", GLFW_KEY_LEFT_SHIFT));
  42. KeyHandler.rebind(ESCAPE, config.getInt("key.escape", GLFW_KEY_ESCAPE));
  43. KeyHandler.rebind(ENTER, config.getInt("key.enter", GLFW_KEY_ENTER));
  44. }
  45. public static void write(SimpleConfig config)
  46. {
  47. config.set("key.up", UP.getKey());
  48. config.set("key.down", DOWN.getKey());
  49. config.set("key.left", LEFT.getKey());
  50. config.set("key.right", RIGHT.getKey());
  51. config.set("key.jump", JUMP.getKey());
  52. config.set("key.run", RUN.getKey());
  53. config.set("key.escape", ESCAPE.getKey());
  54. config.set("key.enter", ENTER.getKey());
  55. }
  56. }