From 56aef90e839abda432cf7fd433ffc549cb13eb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Wed, 23 Apr 2014 01:52:57 +0200 Subject: [PATCH] experiemtnal save fn actualyl working --- .../rogue/screens/ingame/WorldLayer.java | 18 ++++++++++++++++-- src/mightypork/rogue/world/PlayerInfo.java | 8 ++++---- src/mightypork/rogue/world/World.java | 2 ++ src/mightypork/util/ion/Ion.java | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/mightypork/rogue/screens/ingame/WorldLayer.java b/src/mightypork/rogue/screens/ingame/WorldLayer.java index e3722ff..009e766 100644 --- a/src/mightypork/rogue/screens/ingame/WorldLayer.java +++ b/src/mightypork/rogue/screens/ingame/WorldLayer.java @@ -29,10 +29,11 @@ public class WorldLayer extends ScreenLayer { // FIXME just temporary test here final Random rand = new Random(); + final File f = new File(Paths.WORKDIR, "test-world.ion"); final World w = MapGenerator.createWorld(rand.nextLong()); try { - Ion.toFile(new File(Paths.WORKDIR, "test-world.ion"), w); + Ion.toFile(f, w); } catch (final IOException e) { e.printStackTrace(); System.exit(1); @@ -42,7 +43,7 @@ public class WorldLayer extends ScreenLayer { // final World w; // // try { -// w = Ion.fromFile("amap.ion", World.class); +// w = Ion.fromFile(f, World.class); // } catch (IOException e) { // e.printStackTrace(); // System.exit(1); @@ -91,6 +92,19 @@ public class WorldLayer extends ScreenLayer { } }); + bindKey(new KeyStroke(Keys.L_CONTROL, Keys.S), new Runnable() { + + @Override + public void run() + { + try { + Ion.toFile(f, w); + } catch (final IOException e) { + e.printStackTrace(); + } + } + }); + c.addMoveListener(new EntityMoveListener() { private void tryGo(Entity entity) diff --git a/src/mightypork/rogue/world/PlayerInfo.java b/src/mightypork/rogue/world/PlayerInfo.java index 1e85cf3..f7a2337 100644 --- a/src/mightypork/rogue/world/PlayerInfo.java +++ b/src/mightypork/rogue/world/PlayerInfo.java @@ -16,16 +16,16 @@ public class PlayerInfo implements IonBundled { @Override public void load(IonBundle bundle) throws IOException { - eid = bundle.get("attached_eid", 0); - level = bundle.get("current_level", 0); + eid = bundle.get("eid", 0); + level = bundle.get("floor", 0); } @Override public void save(IonBundle bundle) throws IOException { - bundle.put("attached_eid", eid); - bundle.put("current_level", level); + bundle.put("eid", eid); + bundle.put("floor", level); } diff --git a/src/mightypork/rogue/world/World.java b/src/mightypork/rogue/world/World.java index a0ca94e..3130024 100644 --- a/src/mightypork/rogue/world/World.java +++ b/src/mightypork/rogue/world/World.java @@ -38,6 +38,8 @@ public class World implements IonBundled, Updateable { eid = in.get("next_eid", 0); in.loadSequence("levels", levels); in.loadBundled("player", player); + + playerEntity = levels.get(player.getLevel()).getEntity(player.getEID()); } diff --git a/src/mightypork/util/ion/Ion.java b/src/mightypork/util/ion/Ion.java index ab77f80..0fbc28c 100644 --- a/src/mightypork/util/ion/Ion.java +++ b/src/mightypork/util/ion/Ion.java @@ -212,7 +212,7 @@ public class Ion { */ public static T fromStream(InputStream in, Class objClass) throws IOException { - return unwrap(new IonInput(in).readBundle(), objClass); + return unwrap((IonBundle)new IonInput(in).readObject(), objClass); }