Keys.java 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 COMBAT = KeyHandler.register(GLFW_KEY_A);
  17. public final static KeyBinding COMBAT_SWITCH_FACE = KeyHandler.register(GLFW_KEY_S);
  18. public final static KeyBinding COMBAT_DASH = KeyHandler.register(GLFW_KEY_D);
  19. public final static KeyBinding COMBAT_DODGE = KeyHandler.register(GLFW_KEY_F);
  20. public final static KeyBinding COMBAT_BLOCK = KeyHandler.register(GLFW_KEY_G);
  21. public final static KeyBinding COMBAT_ATTACK = KeyHandler.register(GLFW_KEY_H);
  22. private final static KeyBinding[] KEYS =
  23. {
  24. UP, DOWN, LEFT, RIGHT,
  25. JUMP, RUN, ESCAPE, ENTER,
  26. COMBAT, COMBAT_SWITCH_FACE, COMBAT_DASH, COMBAT_DODGE, COMBAT_BLOCK, COMBAT_ATTACK
  27. };
  28. public static void rebind(KeyBinding binding)
  29. {
  30. KeyHandler.rebind(binding);
  31. }
  32. public static int getAmount()
  33. {
  34. return KEYS.length;
  35. }
  36. public static KeyBinding get(int index)
  37. {
  38. return KEYS[index];
  39. }
  40. public static void read(SimpleConfig config)
  41. {
  42. KeyHandler.rebind(UP, config.getInt("key.up", GLFW_KEY_UP));
  43. KeyHandler.rebind(DOWN, config.getInt("key.down", GLFW_KEY_DOWN));
  44. KeyHandler.rebind(LEFT, config.getInt("key.left", GLFW_KEY_LEFT));
  45. KeyHandler.rebind(RIGHT, config.getInt("key.right", GLFW_KEY_RIGHT));
  46. KeyHandler.rebind(JUMP, config.getInt("key.jump", GLFW_KEY_SPACE));
  47. KeyHandler.rebind(RUN, config.getInt("key.run", GLFW_KEY_LEFT_SHIFT));
  48. KeyHandler.rebind(ESCAPE, config.getInt("key.escape", GLFW_KEY_ESCAPE));
  49. KeyHandler.rebind(ENTER, config.getInt("key.enter", GLFW_KEY_ENTER));
  50. KeyHandler.rebind(COMBAT, config.getInt("key.combat", GLFW_KEY_A));
  51. KeyHandler.rebind(COMBAT_SWITCH_FACE, config.getInt("key.combat.switchface", GLFW_KEY_S));
  52. KeyHandler.rebind(COMBAT_DASH, config.getInt("key.combat.dash", GLFW_KEY_D));
  53. KeyHandler.rebind(COMBAT_DODGE, config.getInt("key.combat.dodge", GLFW_KEY_F));
  54. KeyHandler.rebind(COMBAT_BLOCK, config.getInt("key.combat.block", GLFW_KEY_G));
  55. KeyHandler.rebind(COMBAT_ATTACK, config.getInt("key.combat.attack", GLFW_KEY_H));
  56. }
  57. public static void write(SimpleConfig config)
  58. {
  59. config.set("key.up", UP.getKey());
  60. config.set("key.down", DOWN.getKey());
  61. config.set("key.left", LEFT.getKey());
  62. config.set("key.right", RIGHT.getKey());
  63. config.set("key.jump", JUMP.getKey());
  64. config.set("key.run", RUN.getKey());
  65. config.set("key.escape", ESCAPE.getKey());
  66. config.set("key.enter", ENTER.getKey());
  67. config.set("key.combat", COMBAT.getKey());
  68. config.set("key.combat.switchface", COMBAT_SWITCH_FACE.getKey());
  69. config.set("key.combat.dash", COMBAT_DASH.getKey());
  70. config.set("key.combat.dodge", COMBAT_DODGE.getKey());
  71. config.set("key.combat.block", COMBAT_BLOCK.getKey());
  72. config.set("key.combat.attack", COMBAT_ATTACK.getKey());
  73. }
  74. }