Add a button on the deck editor to change your cards to the oldest versions.

This commit is contained in:
emerald000 2020-05-05 01:24:34 -04:00
parent 55a8e34f7a
commit 75bc19d4a7
2 changed files with 78 additions and 0 deletions

View file

@ -12,6 +12,7 @@ import com.j256.ormlite.support.DatabaseConnection;
import com.j256.ormlite.table.TableUtils;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SetType;
import mage.constants.SuperType;
import mage.game.events.Listener;
import mage.util.RandomUtil;
@ -485,6 +486,37 @@ public enum CardRepository {
return Collections.emptyList();
}
public CardInfo findOldestNonPromoVersionCard(String name) {
List<CardInfo> allVersions = this.findCards(name);
if (!allVersions.isEmpty()) {
allVersions.sort(new OldestNonPromoComparator());
return allVersions.get(0);
} else {
return null;
}
}
static class OldestNonPromoComparator implements Comparator<CardInfo> {
@Override
public int compare(CardInfo a, CardInfo b) {
ExpansionInfo aSet = ExpansionRepository.instance.getSetByCode(a.getSetCode());
ExpansionInfo bSet = ExpansionRepository.instance.getSetByCode(b.getSetCode());
if (aSet.getType() == SetType.PROMOTIONAL && bSet.getType() != SetType.PROMOTIONAL) {
return 1;
}
if (bSet.getType() == SetType.PROMOTIONAL && aSet.getType() != SetType.PROMOTIONAL) {
return -1;
}
if (aSet.getReleaseDate().after(bSet.getReleaseDate())) {
return 1;
}
if (aSet.getReleaseDate().before(bSet.getReleaseDate())) {
return -1;
}
return Integer.compare(a.getCardNumberAsInt(), b.getCardNumberAsInt());
}
}
public long getContentVersionFromDB() {
try {
ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL);