Merge pull request #6522 from emerald000/oldVersions

UI: Add a button on the deck editor to change your cards to the oldest versions.
This commit is contained in:
LevelX2 2020-06-24 21:53:42 +02:00 committed by GitHub
commit 0b00ae8b9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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);