public static void preview(GamesInProgress.Info info, Bundle bundle) { info.depth = bundle.getInt(DEPTH); if (info.depth == -1) { info.depth = bundle.getInt("maxDepth"); // FIXME } Hero.preview(info, bundle.getBundle(HERO)); }
@Override public void restoreFromBundle(Bundle bundle) { info = bundle.getString(REASON); win = bundle.getBoolean(WIN); score = bundle.getInt(SCORE); heroClass = HeroClass.restoreInBundle(bundle); armorTier = bundle.getInt(TIER); gameFile = bundle.getString(GAME); // Here lies a collection of messy logic, some to account for transferring pre-0.2.3 rankings // to the new // system, some to account for errors in that process which were patched. // commented here is info about what was added when, and why, eventually after almost everyone // has // dropped 0.2.2 this can be phased out. // 0.2.3, adds depth and parses info, works almost perfectly, except for the edge case in the // next comment. if (!bundle.contains(DEPTH)) { try { depth = Integer.parseInt(info.replaceAll("[\\D]", "")); } catch (Exception e) { depth = 0; } info = info.split("on level")[0].trim(); } else depth = bundle.getInt(DEPTH); // 0.2.3d, fixes a case where a player who died to dm-300 would have a recorded depth of // 30015. if (depth == 30015) depth = 15; // basically every patch until 0.2.3d, extracts the hero's level from the bundle structure. // the second condition in the if is important, helps account for bugged rankings from pre // 0.2.3d if (!bundle.contains(LEVEL) || bundle.getInt(LEVEL) == 0 && ShatteredPixelDungeon.version() < 30) { try { InputStream input = Game.instance.openFileInput(gameFile); Bundle gameBundle = Bundle.read(input); input.close(); herolevel = gameBundle.getBundle("hero").getInt("lvl"); } catch (Exception e) { herolevel = 0; } } else herolevel = bundle.getInt(LEVEL); }
public static void loadGame(String fileName, boolean fullLoad) throws IOException { Bundle bundle = gameBundle(fileName); Dungeon.challenges = bundle.getInt(CHALLENGES); Dungeon.level = null; Dungeon.depth = -1; if (fullLoad) { PathFinder.setMapSize(Level.WIDTH, Level.HEIGHT); } Scroll.restore(bundle); Potion.restore(bundle); Wand.restore(bundle); Ring.restore(bundle); potionOfStrength = bundle.getInt(POS); scrollsOfUpgrade = bundle.getInt(SOU); arcaneStyli = bundle.getInt(AS); dewVial = bundle.getBoolean(DV); transmutation = bundle.getInt(WT); if (fullLoad) { chapters = new HashSet<Integer>(); int ids[] = bundle.getIntArray(CHAPTERS); if (ids != null) { for (int id : ids) { chapters.add(id); } } Bundle quests = bundle.getBundle(QUESTS); if (!quests.isNull()) { Ghost.Quest.restoreFromBundle(quests); WandMaker.Quest.restoreFromBundle(quests); Blacksmith.Quest.restoreFromBundle(quests); Imp.Quest.restoreFromBundle(quests); } else { Ghost.Quest.reset(); WandMaker.Quest.reset(); Blacksmith.Quest.reset(); Imp.Quest.reset(); } Room.restoreRoomsFromBundle(bundle); } Bundle badges = bundle.getBundle(BADGES); if (!badges.isNull()) { Badges.loadLocal(badges); } else { Badges.reset(); } String qsClass = bundle.getString(QUICKSLOT); if (qsClass != null) { try { quickslot = Class.forName(qsClass); } catch (ClassNotFoundException e) { } } else { quickslot = null; } @SuppressWarnings("unused") String version = bundle.getString(VERSION); hero = null; hero = (Hero) bundle.get(HERO); gold = bundle.getInt(GOLD); depth = bundle.getInt(DEPTH); Statistics.restoreFromBundle(bundle); Journal.restoreFromBundle(bundle); }