Keys.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.KeyBinding;
  7. import me.hammerle.snuviengine.api.KeyHandler;
  8. import org.lwjgl.glfw.GLFW;
  9. /**
  10. * A container for all keys
  11. *
  12. * @author julia
  13. */
  14. public class Keys
  15. {
  16. public static final KeyBinding UP_KEY = KeyHandler.register(GLFW.GLFW_KEY_W);
  17. public static final KeyBinding DOWN_KEY = KeyHandler.register(GLFW.GLFW_KEY_S);
  18. public static final KeyBinding LEFT_KEY = KeyHandler.register(GLFW.GLFW_KEY_A);
  19. public static final KeyBinding RIGHT_KEY = KeyHandler.register(GLFW.GLFW_KEY_D);
  20. public static final KeyBinding ZOOM_IN_KEY = KeyHandler.register(GLFW.GLFW_KEY_I);
  21. public static final KeyBinding ZOOM_OUT_KEY = KeyHandler.register(GLFW.GLFW_KEY_O);
  22. public static final KeyBinding CONFIRM_KEY = KeyHandler.register(GLFW.GLFW_KEY_ENTER);
  23. public static final KeyBinding ESCAPE_KEY = KeyHandler.register(GLFW.GLFW_KEY_ESCAPE);
  24. public static final KeyBinding CAM_UP_KEY = KeyHandler.register(GLFW.GLFW_KEY_UP);
  25. public static final KeyBinding CAM_DOWN_KEY = KeyHandler.register(GLFW.GLFW_KEY_DOWN);
  26. public static final KeyBinding CAM_LEFT_KEY = KeyHandler.register(GLFW.GLFW_KEY_LEFT);
  27. public static final KeyBinding CAM_RIGHT_KEY = KeyHandler.register(GLFW.GLFW_KEY_RIGHT);
  28. public static final KeyBinding TEST_KEY = KeyHandler.register(GLFW.GLFW_KEY_T);
  29. public static final KeyBinding OVERLAY_KEY = KeyHandler.register(GLFW.GLFW_KEY_TAB);
  30. public static final KeyBinding BOAT_KEY = KeyHandler.register(GLFW.GLFW_KEY_E);
  31. /**
  32. * An array of all rebindable keys
  33. */
  34. public static final KeyBinding[] KEYS = new KeyBinding[]
  35. {
  36. UP_KEY, DOWN_KEY, LEFT_KEY, RIGHT_KEY, ZOOM_IN_KEY, ZOOM_OUT_KEY,
  37. CAM_UP_KEY, CAM_DOWN_KEY, CAM_LEFT_KEY,
  38. CAM_RIGHT_KEY, OVERLAY_KEY, BOAT_KEY
  39. };
  40. /**
  41. * An array of the names of all rebindable keys
  42. */
  43. public static final String[] KEYNAMES =
  44. {
  45. "Up Key", "Down Key", "Left Key", "Right Key", "Zoom In Key",
  46. "Zoom Out Key", "Cam Up Key", "Cam Down Key", "Cam Left Key",
  47. "Cam Right Key", "Overlay Key", "Boat Key"
  48. };
  49. static
  50. {
  51. File f = new File("resources/config.bin");
  52. if(f.exists())
  53. {
  54. try(DataInputStream reader = new DataInputStream(new FileInputStream(f)))
  55. {
  56. for(int i = 0; i < KEYS.length; ++i)
  57. {
  58. KeyHandler.rebind(KEYS[i], reader.readInt());
  59. }
  60. }
  61. catch(IOException ex)
  62. {
  63. }
  64. }
  65. }
  66. }