Skip to content
Browse files

Make JavaStorage usable immediately after JavaPlatform.register().

  • Loading branch information...
1 parent ff6b128 commit 02688ea31276cb9bd31b565103450b44d7c8c827 @samskivert samskivert committed Jul 13, 2012
Showing with 10 additions and 8 deletions.
  1. +1 −2 java/src/playn/java/JavaPlatform.java
  2. +9 −6 java/src/playn/java/JavaStorage.java
View
3 java/src/playn/java/JavaPlatform.java
@@ -83,7 +83,7 @@ public static JavaPlatform registerHeadless() {
private final JavaAudio audio = new JavaAudio();
private final JavaNet net = new JavaNet(this);
private final JavaRegularExpression regex = new JavaRegularExpression();
- private final JavaStorage storage = new JavaStorage();
+ private final JavaStorage storage = new JavaStorage(this);
private final JsonImpl json = new JsonImpl();
private final JavaKeyboard keyboard = new JavaKeyboard();
private final JavaPointer pointer = new JavaPointer();
@@ -201,7 +201,6 @@ public void openURL(String url) {
public void run(final Game game) {
this.updateRate = game.updateRate();
- storage.init();
try {
// initialize LWJGL (and show the display) now that the game has been initialized
graphics.init();
View
15 java/src/playn/java/JavaStorage.java
@@ -20,7 +20,6 @@
import java.io.FileOutputStream;
import java.util.Properties;
-import playn.core.PlayN;
import playn.core.Storage;
/**
@@ -29,13 +28,17 @@
* TODO(pdr): probably want better handling on where the file is stored
*/
class JavaStorage implements Storage {
+
private static final File tempFile =
new File(new File(System.getProperty("java.io.tmpdir")), "playn.tmp");
+
+ private final JavaPlatform platform;
+ private final Properties properties;
private boolean isPersisted = false; // false by default
- private Properties properties;
- public void init() {
- properties = maybeRetrieveProperties();
+ JavaStorage(JavaPlatform platform) {
+ this.platform = platform;
+ this.properties = maybeRetrieveProperties();
}
@Override
@@ -70,7 +73,7 @@ private void maybePersistProperties(Properties properties) {
properties.store(new FileOutputStream(tempFile), null);
isPersisted = true;
} catch (Exception e) {
- PlayN.log().info("Error persisting properties: " + e.getMessage());
+ platform.log().info("Error persisting properties: " + e.getMessage());
isPersisted = false;
}
}
@@ -82,7 +85,7 @@ private Properties maybeRetrieveProperties() {
properties.load(new FileInputStream(tempFile));
isPersisted = true;
} catch(Exception e) {
- PlayN.log().info("Error retrieving file: " + e.getMessage());
+ platform.log().info("Error retrieving file: " + e.getMessage());
isPersisted = false;
}
} else {

0 comments on commit 02688ea

Please sign in to comment.
Something went wrong with that request. Please try again.