fix problems with deck format detection

This commit is contained in:
Maxmtg
2014-01-13 19:01:46 +00:00
parent 91be7b5a32
commit 4a611fcf58
2 changed files with 15 additions and 4 deletions

View File

@@ -49,12 +49,16 @@ public abstract class StorageReaderFileSections<T> extends StorageReaderBase<T>
}
protected Map<String, T> createMap() {
return new TreeMap<String, T>();
}
/* (non-Javadoc)
* @see forge.util.IItemReader#readAll()
*/
@Override
public Map<String, T> readAll() {
final Map<String, T> result = new TreeMap<String, T>();
final Map<String, T> result = createMap();
int idx = 0;
Iterable<String> file = FileUtil.readFile(this.file);

View File

@@ -195,6 +195,8 @@ public class GameFormat implements Comparable<GameFormat> {
* Instantiates a new format utils.
*/
public static class Reader extends StorageReaderFileSections<GameFormat> {
List<GameFormat> naturallyOrdered = new ArrayList<GameFormat>();
public Reader(File file0) {
super(file0, GameFormat.FN_GET_NAME);
}
@@ -214,13 +216,18 @@ public class GameFormat implements Comparable<GameFormat> {
bannedCards = Arrays.asList(strCars.split("; "));
}
return new GameFormat(title, sets, bannedCards, 1 + idx);
GameFormat result = new GameFormat(title, sets, bannedCards, 1 + idx);
naturallyOrdered.add(result);
return result;
}
}
public static class Collection extends StorageBase<GameFormat> {
public Collection(StorageReaderBase<GameFormat> reader) {
private List<GameFormat> naturallyOrdered;
public Collection(GameFormat.Reader reader) {
super("Format collections", reader);
naturallyOrdered = reader.naturallyOrdered;
}
public GameFormat getStandard() {
@@ -240,7 +247,7 @@ public class GameFormat implements Comparable<GameFormat> {
}
public GameFormat getFormatOfDeck(Deck deck) {
for(GameFormat gf : this) {
for(GameFormat gf : naturallyOrdered) {
if ( Deck.createPredicate(gf.getFilterRules()).apply(deck) )
return gf;
}