mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Formats Comparable sorts formats according to number of sets they include
This commit is contained in:
@@ -21,6 +21,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import forge.game.GameFormat;
|
||||
import forge.util.FileSection;
|
||||
import forge.util.StorageView;
|
||||
import forge.util.StorageReaderFile;
|
||||
|
||||
@@ -93,30 +94,27 @@ public final class FormatCollection extends StorageView<GameFormat> {
|
||||
*/
|
||||
@Override
|
||||
protected GameFormat read(String line) {
|
||||
String name = null;
|
||||
final List<String> sets = new ArrayList<String>(); // default: all
|
||||
// sets
|
||||
// allowed
|
||||
final List<String> sets = new ArrayList<String>(); // default: all sets allowed
|
||||
final List<String> bannedCards = new ArrayList<String>(); // default:
|
||||
// nothing
|
||||
// banned
|
||||
|
||||
final String[] sParts = line.trim().split("\\|");
|
||||
for (final String sPart : sParts) {
|
||||
final String[] kv = sPart.split(":", 2);
|
||||
final String key = kv[0].toLowerCase();
|
||||
if ("name".equals(key)) {
|
||||
name = kv[1];
|
||||
} else if ("sets".equals(key)) {
|
||||
sets.addAll(Arrays.asList(kv[1].split(", ")));
|
||||
} else if ("banned".equals(key)) {
|
||||
bannedCards.addAll(Arrays.asList(kv[1].split("; ")));
|
||||
}
|
||||
FileSection section = FileSection.parse(line, ":", "|");
|
||||
String name = section.get("name");
|
||||
int index = section.getInt("index", 0);
|
||||
String strSets = section.get("sets");
|
||||
if ( null != strSets ) {
|
||||
sets.addAll(Arrays.asList(strSets.split(", ")));
|
||||
}
|
||||
String strCars = section.get("banned");
|
||||
if ( strCars != null ) {
|
||||
bannedCards.addAll(Arrays.asList(strCars.split("; ")));
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
throw new RuntimeException("Format must have a name! Check formats.txt file");
|
||||
}
|
||||
return new GameFormat(name, sets, bannedCards);
|
||||
return new GameFormat(name, sets, bannedCards, index);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ public class GameFormat implements Comparable<GameFormat> {
|
||||
protected final transient Predicate<CardPrinted> filterRules;
|
||||
protected final transient Predicate<CardPrinted> filterPrinted;
|
||||
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Instantiates a new game format.
|
||||
*
|
||||
@@ -58,6 +60,11 @@ public class GameFormat implements Comparable<GameFormat> {
|
||||
* the banned cards
|
||||
*/
|
||||
public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards) {
|
||||
this(fName, sets, bannedCards, 0);
|
||||
}
|
||||
|
||||
public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards, int compareIdx) {
|
||||
this.index = compareIdx;
|
||||
this.name = fName;
|
||||
this.allowedSetCodes = Lists.newArrayList(sets);
|
||||
this.bannedCardNames = bannedCards == null ? new ArrayList<String>() : Lists.newArrayList(bannedCards);
|
||||
@@ -167,13 +174,11 @@ public class GameFormat implements Comparable<GameFormat> {
|
||||
if (null == other) {
|
||||
return 1;
|
||||
}
|
||||
if (name == other.name) {
|
||||
return 0;
|
||||
}
|
||||
if (null == name) {
|
||||
return -1;
|
||||
}
|
||||
return name.compareTo(other.name);
|
||||
return index - other.index;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -235,16 +235,14 @@ public class GuiChoose {
|
||||
public static <T> List<T> sortedGetChoices(final String message, final int min, final int max, final T[] choices, Comparator<T> comparer) {
|
||||
// You may create a copy of source array if callers expect the collection to be unchanged
|
||||
Arrays.sort(choices, comparer);
|
||||
final ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
|
||||
return getChoices(c);
|
||||
return getChoices(message, min, max, choices);
|
||||
}
|
||||
|
||||
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
|
||||
public static <T> List<T> sortedGetChoices(final String message, final int min, final int max, final List<T> choices, Comparator<T> comparer) {
|
||||
// You may create a copy of source list if callers expect the collection to be unchanged
|
||||
Collections.sort(choices, comparer);
|
||||
final ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
|
||||
return getChoices(c);
|
||||
return getChoices(message, min, max, choices);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public final class GameFormatQuest extends GameFormat {
|
||||
* @param allowSetUnlocks
|
||||
*/
|
||||
public GameFormatQuest(final GameFormat toCopy, boolean allowSetUnlocks) {
|
||||
super(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames());
|
||||
super(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames(), toCopy.getIndex());
|
||||
allowUnlocks = allowSetUnlocks;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user