Java Code Examples for com.watabou.utils.Bundle

The following examples show how to use com.watabou.utils.Bundle. These examples are extracted from open source projects. 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 Project: pixel-dungeon   Source File: Wandmaker.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static void restoreFromBundle( Bundle bundle ) {

			Bundle node = bundle.getBundle( NODE );
			
			if (!node.isNull() && (spawned = node.getBoolean( SPAWNED ))) {
				
				type = node.getEnum( TYPE, Type.class );
				if (type == Type.ILLEGAL) {
					type = node.getBoolean( ALTERNATIVE ) ? Type.DUST : Type.BERRY;
				}
				
				given = node.getBoolean( GIVEN );
				
				wand1 = (Wand)node.get( WAND1 );
				wand2 = (Wand)node.get( WAND2 );
			} else {
				reset();
			}
		}
 
Example 2
@Override
public void restoreFromBundle( Bundle bundle ) {
	super.restoreFromBundle(bundle);
	state = bundle.getEnum( STATE, State.class );
	
	//in some states tengu won't be in the world, in others he will be.
	if (state == State.START || state == State.TRAP_MAZES || state == State.FIGHT_PAUSE) {
		tengu = (NewTengu)bundle.get( TENGU );
	} else {
		for (Mob mob : mobs){
			if (mob instanceof NewTengu) {
				tengu = (NewTengu) mob;
				break;
			}
		}
	}
	
	for (Bundlable item : bundle.getCollection(STORED_ITEMS)){
		storedItems.add( (Item)item );
	}
	
	triggered = bundle.getBooleanArray(TRIGGERED);
	
}
 
Example 3
@Override
public void storeInBundle( Bundle bundle ) {
	bundle.put( VERSION, Game.versionCode );
	bundle.put( WIDTH, width );
	bundle.put( HEIGHT, height );
	bundle.put( MAP, map );
	bundle.put( VISITED, visited );
	bundle.put( MAPPED, mapped );
	bundle.put( ENTRANCE, entrance );
	bundle.put( EXIT, exit );
	bundle.put( LOCKED, locked );
	bundle.put( HEAPS, heaps.valueList() );
	bundle.put( PLANTS, plants.valueList() );
	bundle.put( TRAPS, traps.valueList() );
	bundle.put( CUSTOM_TILES, customTiles );
	bundle.put( CUSTOM_WALLS, customWalls );
	bundle.put( MOBS, mobs );
	bundle.put( BLOBS, blobs.values() );
	bundle.put( FEELING, feeling );
	bundle.put( "mobs_to_spawn", mobsToSpawn.toArray(new Class[0]));
}
 
Example 4
@Override
public void restoreFromBundle(Bundle bundle) {
	super.restoreFromBundle(bundle);

	for (CustomTilemap c : customTiles){
		if (c instanceof ArenaVisuals){
			customArenaVisuals = (ArenaVisuals) c;
		}
	}

	//pre-0.8.1 saves that may not have had pylons added
	int gatePos = pointToCell(new Point(gate.left, gate.top));
	if (!locked && solid[gatePos]){

		for (int i : pylonPositions) {
			if (findMob(i) == null) {
				Pylon pylon = new Pylon();
				pylon.pos = i;
				mobs.add(pylon);
			}
		}

	}
}
 
Example 5
Source Project: remixed-dungeon   Source File: Item.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void restoreFromBundle(Bundle bundle) {

	if(id==EntityIdSource.INVALID_ID) {
		id = EntityIdSource.getNextId();
	}

	quantity(bundle.getInt(QUANTITY));

	int level = bundle.getInt(LEVEL);
	if (level > 0) {
		upgrade(level);
	} else if (level < 0) {
		degrade(-level);
	}

	//We still need this because upgrade erase cursed flag
	setCursed(bundle.optBoolean("cursed",false));

	if(quickSlotIndex >= 0 ) {
		QuickSlot.selectItem(this, quickSlotIndex);
	}
}
 
Example 6
@Override
public void storeInBundle( Bundle bundle ) {
	super.storeInBundle(bundle);

	bundle.put( TALKEDTO, talkedTo );
	bundle.put( FIRSTSUMMON, firstSummon );
	bundle.put( GHOSTID, ghostID );
	bundle.put( PETALS, droppedPetals );
	
	if (weapon != null) bundle.put( WEAPON, weapon );
	if (armor != null)  bundle.put( ARMOR, armor );
}
 
Example 7
Source Project: pixel-dungeon   Source File: Bones.java    License: 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
public static void storeInBundle( Bundle bundle ) {
	
	Bundle node = new Bundle();
	
	node.put( SPAWNED, spawned );
	
	if (spawned) {
		node.put( ALTERNATIVE, alternative );
		node.put( GIVEN, given );
		node.put( COMPLETED, completed );
		node.put( REFORGED, reforged );
	}
	
	bundle.put( NODE, node );
}
 
Example 9
@Override
public void storeInBundle(Bundle bundle) {
	super.storeInBundle(bundle);
	bundle.put(TIER, tier);
	bundle.put(WAND_LEVEL, wandLevel);
	bundle.put(TOTAL_ZAPS, totalZaps);
}
 
Example 10
Source Project: remixed-dungeon   Source File: AzuterronNPC.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void storeInBundle( Bundle bundle ) {
	Bundle node = new Bundle();

	node.put(GIVEN, given);
	node.put(DEPTH, depth);
	node.put(PROCESSED, processed);
	node.put(COMPLETED, completed);

	bundle.put( NODE, node );
}
 
Example 11
@SuppressWarnings("unchecked")
@Override
public void restoreFromBundle( Bundle bundle ) {
	super.restoreFromBundle( bundle );
	
	rooms = new ArrayList<>( (Collection<Room>) ((Collection<?>) bundle.getCollection( "rooms" )) );
	for (Room r : rooms) {
		r.onLevelLoad( this );
		if (r instanceof EntranceRoom ){
			roomEntrance = r;
		} else if (r instanceof ExitRoom ){
			roomExit = r;
		}
	}
}
 
Example 12
@SuppressWarnings("unchecked")
@Override
public void restoreFromBundle( Bundle bundle ) {
	if (bundle.contains( ITEMS )) {
		items = new ArrayList<>((Collection<Item>) ((Collection<?>) bundle.getCollection(ITEMS)));
	}
	adjustStats( bundle.getInt( LEVEL ) );
	super.restoreFromBundle(bundle);
}
 
Example 13
Source Project: shattered-pixel-dungeon   Source File: Char.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void restoreFromBundle( Bundle bundle ) {
	
	super.restoreFromBundle( bundle );
	
	pos = bundle.getInt( POS );
	HP = bundle.getInt( TAG_HP );
	HT = bundle.getInt( TAG_HT );
	
	for (Bundlable b : bundle.getCollection( BUFFS )) {
		if (b != null) {
			((Buff)b).attachTo( this );
		}
	}
	
	//pre-0.7.0
	if (bundle.contains( "SHLD" )){
		int legacySHLD = bundle.getInt( "SHLD" );
		//attempt to find the buff that may have given the shield
		ShieldBuff buff = buff(Brimstone.BrimstoneShield.class);
		if (buff != null) legacySHLD -= buff.shielding();
		if (legacySHLD > 0){
			BrokenSeal.WarriorShield buff2 = buff(BrokenSeal.WarriorShield.class);
			if (buff != null) buff2.supercharge(legacySHLD);
		}
	}
}
 
Example 14
Source Project: remixed-dungeon   Source File: Rankings.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void restoreFromBundle( Bundle bundle ) {
	
	info	= bundle.getString  ( REASON );
	win		= bundle.getBoolean ( WIN    );
	score	= bundle.getInt     ( SCORE  );
	
	heroClass	= HeroClass.restoreFromBundle(bundle);

	gameFile	= bundle.getString( GAME );
	mod			= bundle.optString(MOD, ModdingMode.REMIXED);
}
 
Example 15
public static void storeInBundle(Bundle bundle) {
	Float[] genProbs = categoryProbs.values().toArray(new Float[0]);
	float[] storeProbs = new float[genProbs.length];
	for (int i = 0; i < storeProbs.length; i++){
		storeProbs[i] = genProbs[i];
	}
	bundle.put( GENERAL_PROBS, storeProbs);
	
	bundle.put( SPAWNED_ARTIFACTS, spawnedArtifacts.toArray(new Class[0]));
}
 
Example 16
Source Project: remixed-dungeon   Source File: Char.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void storeInBundle(Bundle bundle) {
	super.storeInBundle(bundle);

	bundle.put(TAG_HP, hp());
	bundle.put(TAG_HT, ht());
	bundle.put(BUFFS, buffs);
	bundle.put(SPELLS_USAGE, spellsUsage);

	belongings.storeInBundle(bundle);
}
 
Example 17
Source Project: shattered-pixel-dungeon   Source File: Eye.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void restoreFromBundle(Bundle bundle) {
	super.restoreFromBundle(bundle);
	if (bundle.contains(BEAM_TARGET))
		beamTarget = bundle.getInt(BEAM_TARGET);
	beamCooldown = bundle.getInt(BEAM_COOLDOWN);
	beamCharged = bundle.getBoolean(BEAM_CHARGED);
}
 
Example 18
@Override
public void storeInBundle(Bundle bundle) {
	super.storeInBundle(bundle);
	bundle.put(LAST_ENEMY_POS, lastEnemyPos);
	bundle.put(LEAP_POS, leapPos);
	bundle.put(LEAP_CD, leapCooldown);
}
 
Example 19
public static void restoreRoomsFromBundle( Bundle bundle ) {
	runSpecials.clear();
	if (bundle.contains( ROOMS )) {
		for (Class<? extends Room> type : bundle.getClassArray(ROOMS)) {
			//pre-0.7.0 saves
			if (type != null && type != LaboratoryRoom.class) {
				runSpecials.add(type);
			}
		}
	} else {
		initForRun();
		ShatteredPixelDungeon.reportException(new Exception("specials array didn't exist!"));
	}
	pitNeededDepth = bundle.getInt(PIT);
}
 
Example 20
Source Project: pixel-dungeon   Source File: Alchemy.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void restoreFromBundle( Bundle bundle ) {
	super.restoreFromBundle( bundle );
	
	for (int i=0; i < LENGTH; i++) {
		if (cur[i] > 0) {
			pos = i;
			break;
		}
	}
}
 
Example 21
@Override
public void restoreFromBundle( Bundle bundle ) {
	super.restoreFromBundle(bundle);
	gear = bundle.getInt( GEAR );
	attack = bundle.getInt( ATTACK );
	damage = bundle.getInt( DAMAGE );
}
 
Example 22
Source Project: pixel-dungeon   Source File: MirrorImage.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void storeInBundle( Bundle bundle ) {
	super.storeInBundle( bundle );
	bundle.put( TIER, tier );
	bundle.put( ATTACK, attack );
	bundle.put( DAMAGE, damage );
}
 
Example 23
@Override
public void restoreFromBundle( Bundle bundle ) {
	super.restoreFromBundle(bundle);
	name = bundle.getString( NAME );
	if (bundle.contains(SEEDS))
		Collections.addAll(seeds , bundle.getStringArray(SEEDS));
}
 
Example 24
@Override
public void restoreFromBundle(Bundle bundle) {
	super.restoreFromBundle(bundle);
	lastEnemyPos = bundle.getInt(LAST_ENEMY_POS);
	leapPos = bundle.getInt(LEAP_POS);
	leapCooldown = bundle.getFloat(LEAP_CD);
}
 
Example 25
Source Project: YetAnotherPixelDungeon   Source File: Bag.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void restoreFromBundle( Bundle bundle ) {
	super.restoreFromBundle( bundle );
	for (Bundlable item : bundle.getCollection( ITEMS )) {
           if( item != null)
            ((Item)item).collect( this );
	};
}
 
Example 26
private static void store( Bundle bundle, HashSet<Badge> badges ) {
	int count = 0;
	String names[] = new String[badges.size()];
	
	for (Badge badge:badges) {
		names[count++] = badge.toString();
	}
	bundle.put( BADGES, names );
}
 
Example 27
Source Project: pixel-dungeon   Source File: Weapon.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void storeInBundle( Bundle bundle ) {
	super.storeInBundle( bundle );
	bundle.put( UNFAMILIRIARITY, hitsToKnow );
	bundle.put( ENCHANTMENT, enchantment );
	bundle.put( IMBUE, imbue );
}
 
Example 28
@Override
public void restoreFromBundle( Bundle bundle ) {
	super.restoreFromBundle( bundle );
	levelsToID = bundle.getFloat( LEVELS_TO_ID );
	
	//pre-0.7.2 saves
	if (bundle.contains( "unfamiliarity" )){
		levelsToID = bundle.getInt( "unfamiliarity" ) / 200f;
	}
}
 
Example 29
public static void storeInBundle( Bundle bundle ) {
	bundle.put( GOLD,		goldCollected );
	bundle.put( UPGRADES,	itemsUpgraded );
	bundle.put( DEEPEST,	deepestFloor );
	bundle.put( SLAIN,		enemiesSlain );
	bundle.put( FOOD,		foodEaten );
	bundle.put( ALCHEMY,	potionsCooked );
	bundle.put( PIRANHAS,	piranhasKilled );
	bundle.put( NIGHT,		nightHunt );
	bundle.put( ANKHS,		ankhsUsed );
	bundle.put( DURATION,	duration );
	bundle.put( AMULET,		amuletObtained );
}
 
Example 30
@Override
public void restoreFromBundle(Bundle bundle) {
	super.restoreFromBundle(bundle);
	turnsInvis = bundle.getInt(TURNS);
	if (AttackLevel.getLvl(turnsInvis).blinkDistance > 0){
		ActionIndicator.setAction(this);
	}
}