Keys.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package pathgame.gameplay;
  2. import java.io.DataInputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. import me.hammerle.snuviengine.api.Key;
  7. import org.lwjgl.glfw.GLFW;
  8. public class Keys {
  9. public final Key up;
  10. public final Key down;
  11. public final Key left;
  12. public final Key right;
  13. public final Key zoomIn;
  14. public final Key zoomOut;
  15. public final Key confirm;
  16. public final Key escape;
  17. public final Key cameraUp;
  18. public final Key cameraDown;
  19. public final Key cameraLeft;
  20. public final Key cameraRight;
  21. public final Key test;
  22. public final Key overlay;
  23. public final Key boat;
  24. public final Key[] keys;
  25. public final String[] keyNames = {
  26. "Up Key", "Down Key", "Left Key", "Right Key", "Zoom In Key",
  27. "Zoom Out Key", "Cam Up Key", "Cam Down Key", "Cam Left Key",
  28. "Cam Right Key", "Overlay Key", "Boat Key"
  29. };
  30. private final me.hammerle.snuviengine.api.Keys engineKeys;
  31. public Keys(me.hammerle.snuviengine.api.Keys keys) {
  32. engineKeys = keys;
  33. up = keys.register(GLFW.GLFW_KEY_W);
  34. down = keys.register(GLFW.GLFW_KEY_S);
  35. left = keys.register(GLFW.GLFW_KEY_A);
  36. right = keys.register(GLFW.GLFW_KEY_D);
  37. zoomIn = keys.register(GLFW.GLFW_KEY_I);
  38. zoomOut = keys.register(GLFW.GLFW_KEY_O);
  39. confirm = keys.register(GLFW.GLFW_KEY_ENTER);
  40. escape = keys.register(GLFW.GLFW_KEY_ESCAPE);
  41. cameraUp = keys.register(GLFW.GLFW_KEY_UP);
  42. cameraDown = keys.register(GLFW.GLFW_KEY_DOWN);
  43. cameraLeft = keys.register(GLFW.GLFW_KEY_LEFT);
  44. cameraRight = keys.register(GLFW.GLFW_KEY_RIGHT);
  45. test = keys.register(GLFW.GLFW_KEY_T);
  46. overlay = keys.register(GLFW.GLFW_KEY_TAB);
  47. boat = keys.register(GLFW.GLFW_KEY_E);
  48. this.keys = new Key[]{
  49. up, down, left, right, zoomIn, zoomOut,
  50. cameraUp, cameraDown, cameraLeft,
  51. cameraRight, overlay, boat
  52. };
  53. readConfig();
  54. }
  55. private void readConfig() {
  56. File f = new File("resources/config.bin");
  57. if(!f.exists()) {
  58. return;
  59. }
  60. try(DataInputStream reader = new DataInputStream(new FileInputStream(f))) {
  61. for(Key key : keys) {
  62. engineKeys.rebind(key, reader.readInt());
  63. }
  64. } catch(IOException ex) {
  65. }
  66. }
  67. public void rebind(Key key) {
  68. engineKeys.rebindOnNextKeyPress(key);
  69. }
  70. }