Search in sources :

Example 1 with Bundle

use of com.watabou.utils.Bundle in project pixel-dungeon by watabou.

the class Dungeon method loadGame.

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);
    scrollsOfEnchantment = bundle.getInt(SOE);
    dewVial = bundle.getBoolean(DV);
    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();
    }
    QuickSlot.restore(bundle);
    @SuppressWarnings("unused") String version = bundle.getString(VERSION);
    hero = null;
    hero = (Hero) bundle.get(HERO);
    QuickSlot.compress();
    gold = bundle.getInt(GOLD);
    depth = bundle.getInt(DEPTH);
    Statistics.restoreFromBundle(bundle);
    Journal.restoreFromBundle(bundle);
    droppedItems = new SparseArray<ArrayList<Item>>();
    for (int i = 2; i <= Statistics.deepestFloor + 1; i++) {
        ArrayList<Item> dropped = new ArrayList<Item>();
        for (Bundlable b : bundle.getCollection(String.format(DROPPED, i))) {
            dropped.add((Item) b);
        }
        if (!dropped.isEmpty()) {
            droppedItems.put(i, dropped);
        }
    }
}
Also used : Item(com.watabou.pixeldungeon.items.Item) Bundlable(com.watabou.utils.Bundlable) Bundle(com.watabou.utils.Bundle) ArrayList(java.util.ArrayList)

Example 2 with Bundle

use of com.watabou.utils.Bundle in project pixel-dungeon by watabou.

the class Dungeon method saveGame.

public static void saveGame(String fileName) throws IOException {
    try {
        Bundle bundle = new Bundle();
        bundle.put(VERSION, Game.version);
        bundle.put(CHALLENGES, challenges);
        bundle.put(HERO, hero);
        bundle.put(GOLD, gold);
        bundle.put(DEPTH, depth);
        for (int d : droppedItems.keyArray()) {
            bundle.put(String.format(DROPPED, d), droppedItems.get(d));
        }
        bundle.put(POS, potionOfStrength);
        bundle.put(SOU, scrollsOfUpgrade);
        bundle.put(SOE, scrollsOfEnchantment);
        bundle.put(DV, dewVial);
        int count = 0;
        int[] ids = new int[chapters.size()];
        for (Integer id : chapters) {
            ids[count++] = id;
        }
        bundle.put(CHAPTERS, ids);
        Bundle quests = new Bundle();
        Ghost.Quest.storeInBundle(quests);
        Wandmaker.Quest.storeInBundle(quests);
        Blacksmith.Quest.storeInBundle(quests);
        Imp.Quest.storeInBundle(quests);
        bundle.put(QUESTS, quests);
        Room.storeRoomsInBundle(bundle);
        Statistics.storeInBundle(bundle);
        Journal.storeInBundle(bundle);
        QuickSlot.save(bundle);
        Scroll.save(bundle);
        Potion.save(bundle);
        Wand.save(bundle);
        Ring.save(bundle);
        Bundle badges = new Bundle();
        Badges.saveLocal(badges);
        bundle.put(BADGES, badges);
        OutputStream output = Game.instance.openFileOutput(fileName, Game.MODE_PRIVATE);
        Bundle.write(bundle, output);
        output.close();
    } catch (Exception e) {
        GamesInProgress.setUnknown(hero.heroClass);
    }
}
Also used : Bundle(com.watabou.utils.Bundle) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 3 with Bundle

use of com.watabou.utils.Bundle in project pixel-dungeon by watabou.

the class Dungeon method gameBundle.

public static Bundle gameBundle(String fileName) throws IOException {
    InputStream input = Game.instance.openFileInput(fileName);
    Bundle bundle = Bundle.read(input);
    input.close();
    return bundle;
}
Also used : InputStream(java.io.InputStream) Bundle(com.watabou.utils.Bundle)

Example 4 with Bundle

use of com.watabou.utils.Bundle in project pixel-dungeon by watabou.

the class Badges method saveGlobal.

public static void saveGlobal() {
    Bundle bundle = null;
    if (saveNeeded) {
        bundle = new Bundle();
        store(bundle, global);
        try {
            OutputStream output = Game.instance.openFileOutput(BADGES_FILE, Game.MODE_PRIVATE);
            Bundle.write(bundle, output);
            output.close();
            saveNeeded = false;
        } catch (IOException e) {
        }
    }
}
Also used : Bundle(com.watabou.utils.Bundle) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 5 with Bundle

use of com.watabou.utils.Bundle in project pixel-dungeon by watabou.

the class Badges method loadGlobal.

public static void loadGlobal() {
    if (global == null) {
        try {
            InputStream input = Game.instance.openFileInput(BADGES_FILE);
            Bundle bundle = Bundle.read(input);
            input.close();
            global = restore(bundle);
        } catch (IOException e) {
            global = new HashSet<Badge>();
        }
    }
}
Also used : InputStream(java.io.InputStream) Bundle(com.watabou.utils.Bundle) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

Bundle (com.watabou.utils.Bundle)10 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 OutputStream (java.io.OutputStream)4 Gold (com.watabou.pixeldungeon.items.Gold)1 Item (com.watabou.pixeldungeon.items.Item)1 Ring (com.watabou.pixeldungeon.items.rings.Ring)1 CavesBossLevel (com.watabou.pixeldungeon.levels.CavesBossLevel)1 CavesLevel (com.watabou.pixeldungeon.levels.CavesLevel)1 CityBossLevel (com.watabou.pixeldungeon.levels.CityBossLevel)1 CityLevel (com.watabou.pixeldungeon.levels.CityLevel)1 DeadEndLevel (com.watabou.pixeldungeon.levels.DeadEndLevel)1 HallsBossLevel (com.watabou.pixeldungeon.levels.HallsBossLevel)1 HallsLevel (com.watabou.pixeldungeon.levels.HallsLevel)1 LastLevel (com.watabou.pixeldungeon.levels.LastLevel)1 LastShopLevel (com.watabou.pixeldungeon.levels.LastShopLevel)1 Level (com.watabou.pixeldungeon.levels.Level)1 PrisonBossLevel (com.watabou.pixeldungeon.levels.PrisonBossLevel)1 PrisonLevel (com.watabou.pixeldungeon.levels.PrisonLevel)1 SewerBossLevel (com.watabou.pixeldungeon.levels.SewerBossLevel)1