package pathgame.gameplay; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import me.hammerle.snuviengine.api.Key; import org.lwjgl.glfw.GLFW; public class Keys { public final Key up; public final Key down; public final Key left; public final Key right; public final Key zoomIn; public final Key zoomOut; public final Key confirm; public final Key escape; public final Key cameraUp; public final Key cameraDown; public final Key cameraLeft; public final Key cameraRight; public final Key test; public final Key overlay; public final Key boat; public final Key[] keys; public final String[] keyNames = { "Up Key", "Down Key", "Left Key", "Right Key", "Zoom In Key", "Zoom Out Key", "Cam Up Key", "Cam Down Key", "Cam Left Key", "Cam Right Key", "Overlay Key", "Boat Key" }; private final me.hammerle.snuviengine.api.Keys engineKeys; public Keys(me.hammerle.snuviengine.api.Keys keys) { engineKeys = keys; up = keys.register(GLFW.GLFW_KEY_W); down = keys.register(GLFW.GLFW_KEY_S); left = keys.register(GLFW.GLFW_KEY_A); right = keys.register(GLFW.GLFW_KEY_D); zoomIn = keys.register(GLFW.GLFW_KEY_I); zoomOut = keys.register(GLFW.GLFW_KEY_O); confirm = keys.register(GLFW.GLFW_KEY_ENTER); escape = keys.register(GLFW.GLFW_KEY_ESCAPE); cameraUp = keys.register(GLFW.GLFW_KEY_UP); cameraDown = keys.register(GLFW.GLFW_KEY_DOWN); cameraLeft = keys.register(GLFW.GLFW_KEY_LEFT); cameraRight = keys.register(GLFW.GLFW_KEY_RIGHT); test = keys.register(GLFW.GLFW_KEY_T); overlay = keys.register(GLFW.GLFW_KEY_TAB); boat = keys.register(GLFW.GLFW_KEY_E); this.keys = new Key[]{ up, down, left, right, zoomIn, zoomOut, cameraUp, cameraDown, cameraLeft, cameraRight, overlay, boat }; readConfig(); } private void readConfig() { File f = new File("resources/config.bin"); if(!f.exists()) { return; } try(DataInputStream reader = new DataInputStream(new FileInputStream(f))) { for(Key key : keys) { engineKeys.rebind(key, reader.readInt()); } } catch(IOException ex) { } } public void rebind(Key key) { engineKeys.rebindOnNextKeyPress(key); } }