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

The following examples show how to use com.watabou.utils.Bundle#read() . 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 loadGlobal() {
	if (global == null) {
		try {
			InputStream input = Game.instance.openFileInput( BADGES_FILE );
			Bundle bundle = Bundle.read( input );
			input.close();
			
			global = restore( bundle );
			
		} catch (Exception e) {
			global = new HashSet<>();
		}
	}
	// the following applies the badge as soon as we load our global data
	global.add(Badge.BETA_TESTER); // DSM-xxxx remove this after BETA testing is complete...
}
 
Example 2
Source File: Badges.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
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>();
		}
	}
}
 
Example 3
Source File: Dungeon.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
public static Level loadLevel( HeroClass cl ) throws IOException {
	
	Dungeon.level = null;
	Actor.clear();
	
	InputStream input = Game.instance.openFileInput( Utils.format( depthFile( cl ), depth ) ) ;
	Bundle bundle = Bundle.read( input );
	input.close();
	
	return (Level)bundle.get( "level" );
}
 
Example 4
Source File: Dungeon.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
public static Bundle gameBundle( String fileName ) throws IOException {
	
	InputStream input = Game.instance.openFileInput( fileName );
	Bundle bundle = Bundle.read( input );
	input.close();
	
	return bundle;
}
 
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 Level loadLevel( HeroClass cl ) throws IOException {
	Dungeon.level = null;
	Actor.clear();
	
	InputStream input = Game.instance.openFileInput( Utils.format( depthFile( cl ), depth ) ) ;
	Bundle bundle = Bundle.read( input );
	input.close();
	
	return (Level)bundle.get( "level" );
}
 
Example 6
Source File: Dungeon.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static Bundle gameBundle( String fileName ) throws IOException {
	InputStream input = Game.instance.openFileInput( fileName );
	Bundle bundle = Bundle.read( input );
	input.close();
	
	return bundle;
}
 
Example 7
Source File: Badges.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
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>();
		}
	}
}
 
Example 8
Source File: Dungeon.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static Level loadLevel( HeroClass cl ) throws IOException {
	
	Dungeon.level = null;
	Actor.clear();
	
	InputStream input = Game.instance.openFileInput( Utils.format( depthFile( cl ), depth ) ) ;
	Bundle bundle = Bundle.read( input );
	input.close();
	
	return (Level)bundle.get( "level" );
}
 
Example 9
Source File: Dungeon.java    From pixel-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public static Bundle gameBundle( String fileName ) throws IOException {
	
	InputStream input = Game.instance.openFileInput( fileName );
	Bundle bundle = Bundle.read( input );
	input.close();
	
	return bundle;
}
 
Example 10
Source File: Bones.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
public static Item get() {

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

		if (depth == -1) {
			
			try {

				InputStream input = Game.instance.openFileInput( bonesFile ) ;
				Bundle bundle = Bundle.read( input );
				input.close();
				
				depth = bundle.getInt( LEVEL );
				item = (Item)bundle.get( ITEM );
				
				return get();
				
			} catch (IOException e) {
				return null;
			}
			
		} else {
			if (depth == Dungeon.depth) {
				Game.instance.deleteFile( bonesFile );
				depth = 0;
				
//				if (!item.stackable) {
//					item.cursed = true;
//					item.cursedKnown = true;
//					if (item.isUpgradeable()) {
//						int lvl = (Dungeon.depth - 1) * 3 / 5 + 1;
//						if (lvl < item.bonus) {
//							item.curse( item.bonus - lvl );
//						}
//						item.bonusKnown = false;
//					}
//				}

                item.identify( Item.ITEM_UNKNOWN, true );
				
				if (item instanceof Ring) {
					((Ring)item).syncGem();
				}

//                if (item instanceof Wand) {
//                    ((Wand)item).syncWood();
//                }
				
				return item;
			} else {
				return null;
			}
		}
	}
 
Example 11
Source File: Bones.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public static Item get() {
	if (depth == -1) {
		
		try {
			InputStream input = Game.instance.openFileInput( BONES_FILE ) ;
			Bundle bundle = Bundle.read( input );
			input.close();
			
			depth = bundle.getInt( LEVEL );
			item = (Item)bundle.get( ITEM );
			
			return get();
			
		} catch (IOException e) {
			return null;
		}
		
	} else {
		if (depth == Dungeon.depth) {
			Game.instance.deleteFile( BONES_FILE );
			depth = 0;
			
			if (!item.stackable) {
				item.cursed = true;
				item.cursedKnown = true;
				if (item.isUpgradable()) {
					int lvl = (Dungeon.depth - 1) * 3 / 5 + 1;
					if (lvl < item.level()) {
						item.degrade( item.level() - lvl );
					}
					item.levelKnown = false;
				}
			}
			
			if (item instanceof Ring) {
				((Ring)item).syncGem();
			}
			
			return item;
		} else {
			return null;
		}
	}
}
 
Example 12
Source File: Bones.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public static Item get() {
	if (depth == -1) {
		try {
			InputStream input = Game.instance().openFileInput(BONES_FILE);
			Bundle bundle = Bundle.read(input);
			input.close();

			if (bundle.contains(LEVEL) && bundle.contains(ITEM)) {
				depth = bundle.getInt(LEVEL);
				item = (Item) bundle.get(ITEM);
				return get();
			}
		}  catch (Exception ignored) {
		}
		return CharsList.DUMMY_ITEM;
	} else {
		if (depth == Dungeon.depth) {
			Game.instance().deleteFile( BONES_FILE );
			depth = 0;
			
			if (!item.stackable) {
				item.setCursed(true);
				item.setCursedKnown(true);
				if (item.isUpgradable()) {
					int lvl = (Dungeon.depth - 1) * 3 / 5 + 1;
					if (lvl < item.level()) {
						item.degrade( item.level() - lvl );
					}
					item.setLevelKnown(false);
				}
			}
			
			if (item instanceof Ring) {
				((Ring)item).syncGem();
			}
			
			return item;
		} else {
			return CharsList.DUMMY_ITEM;
		}
	}
}
 
Example 13
Source File: Dungeon.java    From remixed-dungeon with GNU General Public License v3.0 3 votes vote down vote up
public static Bundle gameBundle(String fileName) throws IOException {

        InputStream input = new FileInputStream(FileSystem.getFile(fileName));

        Bundle bundle = Bundle.read(input);
        input.close();

        return bundle;
    }