First improvement to API in convertXitaxMethod simplifying implementation thanks to new CardDb API

This commit is contained in:
leriomaggio
2021-06-09 18:51:08 +01:00
parent 319cb5515c
commit 0c813024d2
3 changed files with 15 additions and 97 deletions

View File

@@ -279,94 +279,14 @@ public class StaticData {
public Predicate<PaperCard> getBrawlPredicate() { return brawlPredicate; }
public String getPreferredCardArt() { return this.commonCards.getCardArtPreference().toString(); }
public void setFilteredHandsEnabled(boolean filteredHandsEnabled){
this.filteredHandsEnabled = filteredHandsEnabled;
}
// TODO: @leriomaggio
// Once the new DB API will be merged, This method will received important refactoring!
public PaperCard getCardByEditionDate(PaperCard card, Date editionDate) {
PaperCard c = this.getCommonCards().getCardFromEditions(card.getName(), CardDb.CardArtPreference.LatestPrintNoPromoNoOnline, card.getArtIndex(), editionDate);
if (null != c) {
return c;
}
c = this.getCommonCards().getCardFromEditions(card.getName(), CardDb.CardArtPreference.LatestPrintNoPromoNoOnline, editionDate);
if (null != c) {
return c;
}
c = this.getCommonCards().getCardFromEditions(card.getName(), CardDb.CardArtPreference.LatestPrint, editionDate);
if (null != c) {
return c;
}
// I give up!
return card;
}
// TODO: @leriomaggio
// Once the new DB API will be merged, these methods are the first to go!
public PaperCard getCardFromLatestorEarliest(PaperCard card) {
PaperCard c = this.getCommonCards().getCardFromEditions(card.getName(), CardDb.CardArtPreference.LatestPrint, card.getArtIndex());
if (null != c && c.hasImage()) {
return c;
}
c = this.getCommonCards().getCardFromEditions(card.getName(), CardDb.CardArtPreference.LatestPrint);
if (null != c && c.hasImage()) {
return c;
}
c = this.getCommonCards().getCardFromEditions(card.getName(), CardDb.CardArtPreference.LatestPrintNoPromoNoOnline);
if (null != c) {
return c;
}
c = this.getCommonCards().getCardFromEditions(card.getName(), CardDb.CardArtPreference.OldPrintNoPromoNoOnline);
if (null != c) {
return c;
}
// I give up!
return card;
}
// TODO: @leriomaggio
// Once the new DB API will be merged, these methods are the first to go!
public PaperCard getCardFromEarliestCoreExp(PaperCard card) {
PaperCard c = this.getCommonCards().getCardFromEditions(card.getName(), CardDb.CardArtPreference.OldPrintNoPromoNoOnline, card.getArtIndex());
if (null != c && c.hasImage()) {
return c;
}
c = this.getCommonCards().getCardFromEditions(card.getName(), CardDb.CardArtPreference.OldPrintNoPromoNoOnline);
if (null != c && c.hasImage()) {
return c;
}
c = this.getCommonCards().getCardFromEditions(card.getName(), CardDb.CardArtPreference.OldPrint);
if (null != c) {
return c;
}
// I give up!
return card;
public PaperCard getReplacementCard(PaperCard card, final Date setReleasedBefore) {
PaperCard c = this.getCommonCards().getCardFromEditions(card.getName(), card.getArtIndex(), setReleasedBefore);
// NOTE: if c is null, is necessarily due to the artIndex, so remove it!
return c != null ? c : this.getCommonCards().getCardFromEditions(card.getName(), setReleasedBefore);
}
public boolean getFilteredHandsEnabled(){

View File

@@ -534,12 +534,21 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
/* Get Card from Edition using the default `CardArtPreference`
NOTE: this method has NOT been included in the Interface API refactoring as it
relies on a specific (new) attribute included in the `CardDB` that sets the
default `ArtPreference`. The method is public, though, for future use.
default `ArtPreference`. This attribute does not necessarily belongs to any
class implementing ICardInterface, and so the not inclusion in the API
*/
public PaperCard getCardFromEditions(final String cardName) {
return this.getCardFromEditions(cardName, this.defaultCardArtPreference);
}
public PaperCard getCardFromEditions(final String cardName, final Date printedBefore) {
return this.getCardFromEditions(cardName, this.defaultCardArtPreference, IPaperCard.NO_ART_INDEX, printedBefore);
}
public PaperCard getCardFromEditions(final String cardName, final int artIndex, final Date printedBefore) {
return this.getCardFromEditions(cardName, this.defaultCardArtPreference, artIndex, printedBefore);
}
@Override
public PaperCard getCardFromEditions(final String cardName, CardArtPreference artPreference) {
return getCardFromEditions(cardName, artPreference, IPaperCard.NO_ART_INDEX, null);

View File

@@ -252,8 +252,6 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
private void convertByXitaxMethod() {
Date dateWithAllCards = StaticData.instance().getEditions().getEarliestDateWithAllCards(getAllCardsInASinglePool());
String artOption = StaticData.instance().getPreferredCardArt();
for(Entry<DeckSection, CardPool> p : parts.entrySet()) {
if( p.getKey() == DeckSection.Planes || p.getKey() == DeckSection.Schemes || p.getKey() == DeckSection.Avatar)
continue;
@@ -265,16 +263,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
int count = cp.getValue();
PaperCard replacementCard;
switch (artOption) {
case "Latest":
replacementCard = StaticData.instance().getCardFromLatestorEarliest(card);
break;
case "Earliest":
replacementCard = StaticData.instance().getCardFromEarliestCoreExp(card);
break;
default:
replacementCard = StaticData.instance().getCardByEditionDate(card, dateWithAllCards);
}
replacementCard = StaticData.instance().getReplacementCard(card, dateWithAllCards);
// Note @leriomaggio: The following logic is very obscure to me
// Why looking for a replacement Card and then not using adding it to the pool?