Skip to content

Commit

Permalink
Make JavaStorage usable immediately after JavaPlatform.register().
Browse files Browse the repository at this point in the history
  • Loading branch information
samskivert committed Jul 13, 2012
1 parent ff6b128 commit 02688ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 1 addition & 2 deletions java/src/playn/java/JavaPlatform.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static JavaPlatform registerHeadless() {
private final JavaAudio audio = new JavaAudio(); private final JavaAudio audio = new JavaAudio();
private final JavaNet net = new JavaNet(this); private final JavaNet net = new JavaNet(this);
private final JavaRegularExpression regex = new JavaRegularExpression(); 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 JsonImpl json = new JsonImpl();
private final JavaKeyboard keyboard = new JavaKeyboard(); private final JavaKeyboard keyboard = new JavaKeyboard();
private final JavaPointer pointer = new JavaPointer(); private final JavaPointer pointer = new JavaPointer();
Expand Down Expand Up @@ -201,7 +201,6 @@ public void openURL(String url) {
public void run(final Game game) { public void run(final Game game) {
this.updateRate = game.updateRate(); this.updateRate = game.updateRate();


storage.init();
try { try {
// initialize LWJGL (and show the display) now that the game has been initialized // initialize LWJGL (and show the display) now that the game has been initialized
graphics.init(); graphics.init();
Expand Down
15 changes: 9 additions & 6 deletions java/src/playn/java/JavaStorage.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.Properties; import java.util.Properties;


import playn.core.PlayN;
import playn.core.Storage; import playn.core.Storage;


/** /**
Expand All @@ -29,13 +28,17 @@
* TODO(pdr): probably want better handling on where the file is stored * TODO(pdr): probably want better handling on where the file is stored
*/ */
class JavaStorage implements Storage { class JavaStorage implements Storage {

private static final File tempFile = private static final File tempFile =
new File(new File(System.getProperty("java.io.tmpdir")), "playn.tmp"); 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 boolean isPersisted = false; // false by default
private Properties properties;


public void init() { JavaStorage(JavaPlatform platform) {
properties = maybeRetrieveProperties(); this.platform = platform;
this.properties = maybeRetrieveProperties();
} }


@Override @Override
Expand Down Expand Up @@ -70,7 +73,7 @@ private void maybePersistProperties(Properties properties) {
properties.store(new FileOutputStream(tempFile), null); properties.store(new FileOutputStream(tempFile), null);
isPersisted = true; isPersisted = true;
} catch (Exception e) { } catch (Exception e) {
PlayN.log().info("Error persisting properties: " + e.getMessage()); platform.log().info("Error persisting properties: " + e.getMessage());
isPersisted = false; isPersisted = false;
} }
} }
Expand All @@ -82,7 +85,7 @@ private Properties maybeRetrieveProperties() {
properties.load(new FileInputStream(tempFile)); properties.load(new FileInputStream(tempFile));
isPersisted = true; isPersisted = true;
} catch(Exception e) { } catch(Exception e) {
PlayN.log().info("Error retrieving file: " + e.getMessage()); platform.log().info("Error retrieving file: " + e.getMessage());
isPersisted = false; isPersisted = false;
} }
} else { } else {
Expand Down

0 comments on commit 02688ea

Please sign in to comment.