Java Code Examples for com.watabou.utils.Bundle#write()

The following examples show how to use com.watabou.utils.Bundle#write() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Badges.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static void saveGlobal() {
	if (saveNeeded) {
		
		Bundle 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) {
			
		}
	}
}
 
Example 2
Source File: Bones.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static void leave() {

		depth = Dungeon.depth;

		//heroes which have won the game, who die far above their farthest depth, or who are challenged drop no bones.
		if (Statistics.amuletObtained || (Statistics.deepestFloor - 5) >= depth || Dungeon.challenges > 0) {
			depth = -1;
			return;
		}

		item = pickItem(Dungeon.hero);

		Bundle bundle = new Bundle();
		bundle.put( LEVEL, depth );
		bundle.put( ITEM, item );

		try {
			OutputStream output = Game.instance.openFileOutput( BONES_FILE, Game.MODE_PRIVATE );
			Bundle.write( bundle, output );
			output.close();
		} catch (IOException e) {

		}
	}
 
Example 3
Source File: Badges.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public static void saveGlobal() {
	if (ModdingMode.inMod()) {
		return;
	}

	if (saveNeeded) {
		Bundle bundle = new Bundle();
		store(bundle, global);

		try {
			OutputStream output = FileSystem.getOutputStream(BADGES_FILE);
			Bundle.write(bundle, output);
			output.close();

			saveNeeded = false;
		} catch (IOException e) {
			EventCollector.logException(e, "Badges.saveGlobal");
		}
	}
}
 
Example 4
Source File: Dungeon.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
public static void saveLevel() throws IOException {
	Bundle bundle = new Bundle();
	bundle.put( LEVEL, level );
	
	OutputStream output = Game.instance.openFileOutput( Utils.format( depthFile( hero.heroClass ), depth ), Game.MODE_PRIVATE );
	Bundle.write( bundle, output );
	output.close();
}
 
Example 5
Source File: Dungeon.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static void saveLevel() throws IOException {
	Bundle bundle = new Bundle();
	bundle.put(LEVEL, level);

	OutputStream output = Game.instance.openFileOutput(
		Utils.format( depthFile( hero.heroClass ), depth ), Game.MODE_PRIVATE );
	Bundle.write( bundle, output );
	output.close();
}
 
Example 6
Source File: Dungeon.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static void saveLevel() throws IOException {
	Bundle bundle = new Bundle();
	bundle.put( LEVEL, level );
	
	OutputStream output = Game.instance.openFileOutput( Utils.format( depthFile( hero.heroClass ), depth ), Game.MODE_PRIVATE );
	Bundle.write( bundle, output );
	output.close();
}
 
Example 7
Source File: Bones.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static void leave() {
	
	item = null;
	switch (Random.Int( 4 )) {
	case 0:
		item = Dungeon.hero.belongings.weapon;
		break;
	case 1:
		item = Dungeon.hero.belongings.armor;
		break;
	case 2:
		item = Dungeon.hero.belongings.ring1;
		break;
	case 3:
		item = Dungeon.hero.belongings.ring2;
		break;
	}
	if (item == null) {
		if (Dungeon.gold > 0) {
			item = new Gold( Random.IntRange( 1, Dungeon.gold ) );
		} else {
			item = new Gold( 1 );
		}
	}
	
	depth = Dungeon.depth;
	
	Bundle bundle = new Bundle();
	bundle.put( LEVEL, depth );
	bundle.put( ITEM, item );
	
	try {
		OutputStream output = Game.instance.openFileOutput( BONES_FILE, Game.MODE_PRIVATE );
		Bundle.write( bundle, output );
		output.close();
	} catch (IOException e) {

	}
}
 
Example 8
Source File: Dungeon.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
@SneakyThrows
private static void saveLevel(String saveTo, Level level) {
    Bundle bundle = new Bundle();
    bundle.put(LEVEL, level);

    bundle.put(SCRIPTS_DATA,
            LuaEngine.getEngine().require(LuaEngine.SCRIPTS_LIB_STORAGE).get("serializeLevelData").call().checkjstring());


    OutputStream output = FileSystem.getOutputStream(saveTo);
    Bundle.write(bundle, output);
    output.close();
}
 
Example 9
Source File: Bones.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static void leave() {
	
	item = CharsList.DUMMY_ITEM;

	switch (Random.Int( 4 )) {
	case 0:
		item = Dungeon.hero.getBelongings().weapon;
		break;
	case 1:
		item = Dungeon.hero.getBelongings().armor;
		break;
	case 2:
		item = Dungeon.hero.getBelongings().ring1;
		break;
	case 3:
		item = Dungeon.hero.getBelongings().ring2;
		break;
	}
	if (item == CharsList.DUMMY_ITEM || (item instanceof Artifact && !(item instanceof Ring))) {
		if (Dungeon.hero.gold() > 0) {
			item = new Gold( Random.IntRange( 1, Dungeon.hero.gold()) );
		} else {
			item = new Gold( 1 );
		}
	}
	
	depth = Dungeon.depth;
	
	Bundle bundle = new Bundle();
	bundle.put( LEVEL, depth );
	bundle.put( ITEM, item );

	try {
		OutputStream output = FileSystem.getOutputStream(BONES_FILE);
		Bundle.write( bundle, output );
		output.close();
	} catch (IOException ignored) {

	}
}
 
Example 10
Source File: Dungeon.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
public static void saveGame( String fileName ) throws IOException {
	try {
		Bundle bundle = new Bundle();
		
		bundle.put( VERSION, Game.version );
		bundle.put( DIFFICULTY, difficulty );
		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( POE, potionOfExperience );
		bundle.put( SOU, scrollsOfUpgrade );
		bundle.put( SOE, scrollsOfEnchantment );

		bundle.put( ANKHS, ankhs );
		bundle.put( WANDS, wands );
		bundle.put( RINGS, rings );
		bundle.put( AMMOS, ammos );

		bundle.put( BOTTLES, bottles );
		bundle.put( SCROLLS, scrolls );
		bundle.put( TORCHES, torches );

		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 );
		AmbitiousImp.Quest.storeInBundle( quests );
		bundle.put( QUESTS, quests );
		
		Room.storeRoomsInBundle( bundle );

           ShopPainter.saveAssortment( 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 );
	}
}
 
Example 11
Source File: Bones.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
public static void leave() {
	
	item = null;
	switch (Random.Int( 5 )) {
	case 0:
		item = Dungeon.hero.belongings.weap1;
		break;
	case 1:
           item = Dungeon.hero.belongings.weap2;
           break;
       case 2:
           item = Dungeon.hero.belongings.armor;
		break;
	case 3:
		item = Dungeon.hero.belongings.ring1;
		break;
	case 4:
		item = Dungeon.hero.belongings.ring2;
		break;
	}

	if (item == null) {
		if (Dungeon.gold > 0) {
			item = new Gold( Random.IntRange( 1, Dungeon.gold ) );
		} else {
			item = new Gold( 1 );
		}
	}
	
	depth = Dungeon.depth;
	
	Bundle bundle = new Bundle();
	bundle.put( LEVEL, Statistics.deepestFloor );
	bundle.put( ITEM, item );

       String bonesFile = Utils.format( BONES_FILE, Dungeon.difficulty );

	try {
		OutputStream output = Game.instance.openFileOutput( bonesFile, Game.MODE_PRIVATE );
		Bundle.write( bundle, output );
		output.close();
	} catch (IOException e) {

	}
}
 
Example 12
Source File: Dungeon.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
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 );
	}
}
 
Example 13
Source File: Dungeon.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public static void saveGame(String fileName) throws IOException {
    Bundle bundle = new Bundle();

    bundle.put(GAME_ID, gameId);
    bundle.put(VERSION, Game.version);
    bundle.put(HERO, hero);
    bundle.put(DEPTH, depth);

    bundle.put(POS, potionOfStrength);
    bundle.put(SOU, scrollsOfUpgrade);
    bundle.put(AS, arcaneStyli);
    bundle.put(DV, dewVial);
    bundle.put(WT, transmutation);

    bundle.put(REALTIME, realtime);
    bundle.put(CHALLENGES, getChallenges());

    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);
    AzuterronNPC.Quest.storeInBundle(quests);
    ScarecrowNPC.Quest.storeInBundle(quests);
    CagedKobold.Quest.storeInBundle(quests);
    PlagueDoctorNPC.Quest.storeInBundle(quests);
    bundle.put(QUESTS, quests);

    Room.storeRoomsInBundle(bundle);

    Statistics.storeInBundle(bundle);
    Journal.storeInBundle(bundle);
    Logbook.storeInBundle(bundle);

    Scroll.save(bundle);
    Potion.save(bundle);
    Wand.save(bundle);
    Ring.save(bundle);
    QuickSlot.save(bundle);

    Bundle badges = new Bundle();
    Badges.saveLocal(badges);
    bundle.put(BADGES, badges);

    bundle.put(MOVE_TIMEOUT, moveTimeoutIndex);

    bundle.put(SCRIPTS_DATA,
            LuaEngine.getEngine().require(LuaEngine.SCRIPTS_LIB_STORAGE).get("serializeGameData").call().checkjstring());

    bundle.put(LAST_USED_ID, EntityIdSource.getNextId());
    bundle.put(MOD, ModdingMode.activeMod());

    OutputStream output = FileSystem.getOutputStream(fileName);
    Bundle.write(bundle, output);
    output.close();
}