Java Code Examples for com.watabou.utils.Bundlable

The following examples show how to use com.watabou.utils.Bundlable. 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
@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.MAZE) {
		tengu = (OldTengu)bundle.get( TENGU );
	} else {
		for (Mob mob : mobs){
			if (mob instanceof OldTengu) {
				tengu = (OldTengu) mob;
				break;
			}
		}
	}

	for (Bundlable item : bundle.getCollection(STORED_ITEMS)){
		storedItems.add( (Item)item );
	}
}
 
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 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.MAZE) {
		tengu = (OldTengu)bundle.get( TENGU );
	} else {
		for (Mob mob : mobs){
			if (mob instanceof OldTengu) {
				tengu = (OldTengu) mob;
				break;
			}
		}
	}

	for (Bundlable item : bundle.getCollection(STORED_ITEMS)){
		storedItems.add( (Item)item );
	}
}
 
Example 4
Source Project: YetAnotherPixelDungeon   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).attachOnLoad( this );
		}
	}
}
 
Example 5
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 6
Source Project: unleashed-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 );
		}
	}
}
 
Example 7
public void restorePlaceholders(Bundle bundle){
	Collection<Bundlable> placeholders = bundle.getCollection(PLACEHOLDERS);
	boolean[] placements = bundle.getBooleanArray( PLACEMENTS );

	int i = 0;
	for (Bundlable item : placeholders){
		while (!placements[i]) i++;
		setSlot( i, (Item)item );
		i++;
	}

}
 
Example 8
Source Project: unleashed-pixel-dungeon   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 9
Source Project: 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 );
		}
	}
}
 
Example 10
Source Project: pixel-dungeon   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 )) {
		((Item)item).collect( this );
	};
}
 
Example 11
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 12
public void restorePlaceholders(Bundle bundle){
	Collection<Bundlable> placeholders = bundle.getCollection(PLACEHOLDERS);
	boolean[] placements = bundle.getBooleanArray( PLACEMENTS );

	int i = 0;
	for (Bundlable item : placeholders){
		while (!placements[i]) i++;
		setSlot( i, (Item)item );
		i++;
	}

}
 
Example 13
Source Project: shattered-pixel-dungeon   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 14
@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 15
@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) {
		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);
	
	//compatibility with pre-0.7.5a saves
	if (state == State.WON){
		int cell = pointToCell(endStart);
		int i = 0;
		while (cell < length()){
			System.arraycopy(endMap, i, map, cell, 14);
			i += 14;
			cell += width();
		}
		exit = pointToCell(levelExit);
	}
}
 
Example 16
public void restorePlaceholders(Bundle bundle){
	Collection<Bundlable> placeholders = bundle.getCollection(PLACEHOLDERS);
	boolean[] placements = bundle.getBooleanArray( PLACEMENTS );

	int i = 0;
	for (Bundlable item : placeholders){
		while (!placements[i]) i++;
		setSlot( i, (Item)item );
		i++;
	}

}
 
Example 17
@Override
public void restoreFromBundle( Bundle bundle ) {
	super.restoreFromBundle( bundle );
	for (Bundlable item : bundle.getCollection( ITEMS )) {
		if (item != null) ((Item)item).collect( this );
	}
}
 
Example 18
public static void restoreFromBundle( Bundle bundle ) {
	records = new ArrayList<Record>();
	for (Bundlable rec : bundle.getCollection( JOURNAL ) ) {
		records.add( (Record) rec );
	}
}
 
Example 19
Source Project: YetAnotherPixelDungeon   Source File: Level.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void restoreFromBundle( Bundle bundle ) {

       heaps = new SparseArray<Heap>();
       hazards = new HashSet<Hazard>();
       mobs = new HashSet<Mob>();
       blobs = new HashMap<Class<? extends Blob>, Blob>();

	map		= bundle.getIntArray( MAP );
	visited	= bundle.getBooleanArray( VISITED );
	mapped	= bundle.getBooleanArray( MAPPED );

	mobsSpawned = bundle.getInt(MOBS_SPAWNED);

	entrance	= bundle.getInt( ENTRANCE );
	exit		= bundle.getInt( EXIT );

	weakFloorCreated = false;

	adjustMapSize();

	Collection<Bundlable> collection = bundle.getCollection( HEAPS );
	for (Bundlable h : collection) {
		Heap heap = (Heap)h;
           if( heap != null ){
               if( resizingNeeded ){
                   heap.pos = adjustPos( heap.pos );
               }
               heaps.put( heap.pos, heap );
           }
	}

	collection = bundle.getCollection( HAZARDS );
	for (Bundlable z : collection) {
           Hazard hazard = (Hazard)z;
           if (hazard != null){
               if( resizingNeeded ){
                   hazard.pos = adjustPos( hazard.pos );
               }
               hazards.add( hazard );
           }
	}

	collection = bundle.getCollection( MOBS );
	for (Bundlable m : collection) {
		Mob mob = (Mob)m;
		if (mob != null) {
			if (resizingNeeded) {
				mob.pos = adjustPos( mob.pos );
			}
			mobs.add( mob );
		}
	}

	collection = bundle.getCollection( BLOBS );
	for (Bundlable b : collection) {
		Blob blob = (Blob)b;
		blobs.put( blob.getClass(), blob );
	}

	buildFlagMaps();
	cleanWalls();
}
 
Example 20
public static void restoreFromBundle( Bundle bundle ) {
	records = new ArrayList<>();
	for (Bundlable rec : bundle.getCollection( JOURNAL ) ) {
		records.add( (Record) rec );
	}
}
 
Example 21
Source Project: pixel-dungeon   Source File: Journal.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static void restoreFromBundle( Bundle bundle ) {
	records = new ArrayList<Record>();
	for (Bundlable rec : bundle.getCollection( JOURNAL ) ) {
		records.add( (Record) rec );
	}
}
 
Example 22
Source Project: pixel-dungeon   Source File: Dungeon.java    License: GNU General Public License v3.0 4 votes vote down vote up
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 );
		}
	}
}
 
Example 23
Source Project: pixel-dungeon   Source File: Level.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void restoreFromBundle( Bundle bundle ) {
	
	mobs = new HashSet<Mob>();
	heaps = new SparseArray<Heap>();
	blobs = new HashMap<Class<? extends Blob>, Blob>();
	plants = new SparseArray<Plant>();
	
	map		= bundle.getIntArray( MAP );
	visited	= bundle.getBooleanArray( VISITED );
	mapped	= bundle.getBooleanArray( MAPPED );
	
	entrance	= bundle.getInt( ENTRANCE );
	exit		= bundle.getInt( EXIT );
	
	weakFloorCreated = false;
	
	adjustMapSize();
	
	Collection<Bundlable> collection = bundle.getCollection( HEAPS );
	for (Bundlable h : collection) {
		Heap heap = (Heap)h;
		if (resizingNeeded) {
			heap.pos = adjustPos( heap.pos );
		}
		heaps.put( heap.pos, heap );
	}
	
	collection = bundle.getCollection( PLANTS );
	for (Bundlable p : collection) {
		Plant plant = (Plant)p;
		if (resizingNeeded) {
			plant.pos = adjustPos( plant.pos );
		}
		plants.put( plant.pos, plant );
	}
	
	collection = bundle.getCollection( MOBS );
	for (Bundlable m : collection) {
		Mob mob = (Mob)m;
		if (mob != null) {
			if (resizingNeeded) {
				mob.pos = adjustPos( mob.pos );
			}
			mobs.add( mob );
		}
	}
	
	collection = bundle.getCollection( BLOBS );
	for (Bundlable b : collection) {
		Blob blob = (Blob)b;
		blobs.put( blob.getClass(), blob );
	}
	
	buildFlagMaps();
	cleanWalls();
}
 
Example 24
public static void restoreFromBundle( Bundle bundle ) {
	records = new ArrayList<>();
	for (Bundlable rec : bundle.getCollection( RECORDS ) ) {
		records.add( (Record) rec );
	}
}
 
Example 25
public static void restoreFromBundle( Bundle bundle ) {
	records = new ArrayList<>();
	for (Bundlable rec : bundle.getCollection( RECORDS ) ) {
		records.add( (Record) rec );
	}
}