User modified keybindings are persistently saved
- Works on windows computers - KeyFactory processes its own XML saving/loading - Does not work with Jar yet - Changed keyFactory to static temporarily to work with existing FXML loading architecture #story[1197]
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package visualiser.gameController.Keys;
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
import java.beans.XMLEncoder;
|
||||
import java.io.*;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -62,4 +66,43 @@ public class KeyFactory {
|
||||
keyState.put(newKey, controlKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Persistently saves the keybindings the user has set.
|
||||
*/
|
||||
public void save(){
|
||||
try {
|
||||
XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
|
||||
new FileOutputStream(getClass().getResource(
|
||||
"/visualiser/userSettings/keyFactory.xml")
|
||||
.toURI().getPath())));
|
||||
encoder.writeObject(this.keyState);
|
||||
encoder.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the persistently saved keybindings the user has set.
|
||||
*/
|
||||
public void load(){
|
||||
try {
|
||||
XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(
|
||||
new FileInputStream(getClass().getResource(
|
||||
"/visualiser/userSettings/keyFactory.xml")
|
||||
.toURI().getPath())));
|
||||
|
||||
Map<String, ControlKey> savedKeyState
|
||||
= (Map<String, ControlKey>)decoder.readObject();
|
||||
decoder.close();
|
||||
this.keyState = savedKeyState;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user