v0.4.1: massively improved the efficiency of rankings storage
This commit is contained in:
@@ -24,8 +24,10 @@ import com.watabou.utils.Bundle;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemStatusHandler<T extends Item> {
|
||||
|
||||
@@ -80,8 +82,22 @@ public class ItemStatusHandler<T extends Item> {
|
||||
}
|
||||
}
|
||||
|
||||
public void saveSelectively( Bundle bundle, ArrayList<Item> itemsToSave ){
|
||||
List<Class<? extends T>> items = Arrays.asList(this.items);
|
||||
for (Item item : itemsToSave){
|
||||
if (items.contains(item.getClass())){
|
||||
Class<? extends T> cls = items.get(items.indexOf(item.getClass()));
|
||||
String itemName = cls.toString();
|
||||
bundle.put( itemName + PFX_LABEL, itemLabels.get( cls ) );
|
||||
bundle.put( itemName + PFX_KNOWN, known.contains( cls ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void restore( Bundle bundle, ArrayList<String> labelsLeft ) {
|
||||
|
||||
ArrayList<Class<? extends T>> unlabelled = new ArrayList<>();
|
||||
|
||||
for (int i=0; i < items.length; i++) {
|
||||
|
||||
Class<? extends T> item = items[i];
|
||||
@@ -99,14 +115,22 @@ public class ItemStatusHandler<T extends Item> {
|
||||
|
||||
} else {
|
||||
|
||||
int index = Random.Int( labelsLeft.size() );
|
||||
unlabelled.add(items[i]);
|
||||
|
||||
itemLabels.put( item, labelsLeft.get( index ) );
|
||||
labelsLeft.remove( index );
|
||||
}
|
||||
}
|
||||
|
||||
if (bundle.contains( itemName + PFX_KNOWN ) && bundle.getBoolean( itemName + PFX_KNOWN )) {
|
||||
known.add( item );
|
||||
}
|
||||
for (Class<? extends T> item : unlabelled){
|
||||
|
||||
String itemName = item.toString();
|
||||
|
||||
int index = Random.Int( labelsLeft.size() );
|
||||
|
||||
itemLabels.put( item, labelsLeft.get( index ) );
|
||||
labelsLeft.remove( index );
|
||||
|
||||
if (bundle.contains( itemName + PFX_KNOWN ) && bundle.getBoolean( itemName + PFX_KNOWN )) {
|
||||
known.add( item );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,10 @@ public class Potion extends Item {
|
||||
public static void save( Bundle bundle ) {
|
||||
handler.save( bundle );
|
||||
}
|
||||
|
||||
public static void saveSelectively( Bundle bundle, ArrayList<Item> items ) {
|
||||
handler.saveSelectively( bundle, items );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void restore( Bundle bundle ) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.ItemStatusHandler;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc;
|
||||
@@ -36,6 +35,7 @@ import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
|
||||
import com.watabou.utils.Bundle;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Ring extends KindofMisc {
|
||||
@@ -89,6 +89,10 @@ public class Ring extends KindofMisc {
|
||||
public static void save( Bundle bundle ) {
|
||||
handler.save( bundle );
|
||||
}
|
||||
|
||||
public static void saveSelectively( Bundle bundle, ArrayList<Item> items ) {
|
||||
handler.saveSelectively( bundle, items );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void restore( Bundle bundle ) {
|
||||
|
||||
@@ -95,7 +95,11 @@ public abstract class Scroll extends Item {
|
||||
public static void save( Bundle bundle ) {
|
||||
handler.save( bundle );
|
||||
}
|
||||
|
||||
|
||||
public static void saveSelectively( Bundle bundle, ArrayList<Item> items ) {
|
||||
handler.saveSelectively( bundle, items );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void restore( Bundle bundle ) {
|
||||
handler = new ItemStatusHandler<>( (Class<? extends Scroll>[])scrolls, runes, bundle );
|
||||
|
||||
Reference in New Issue
Block a user