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 Predicate<PaperCard> getBrawlPredicate() { return brawlPredicate; }
public String getPreferredCardArt() { return this.commonCards.getCardArtPreference().toString(); }
public void setFilteredHandsEnabled(boolean filteredHandsEnabled){ public void setFilteredHandsEnabled(boolean filteredHandsEnabled){
this.filteredHandsEnabled = filteredHandsEnabled; this.filteredHandsEnabled = filteredHandsEnabled;
} }
// TODO: @leriomaggio public PaperCard getReplacementCard(PaperCard card, final Date setReleasedBefore) {
// Once the new DB API will be merged, This method will received important refactoring! PaperCard c = this.getCommonCards().getCardFromEditions(card.getName(), card.getArtIndex(), setReleasedBefore);
public PaperCard getCardByEditionDate(PaperCard card, Date editionDate) { // NOTE: if c is null, is necessarily due to the artIndex, so remove it!
return c != null ? c : this.getCommonCards().getCardFromEditions(card.getName(), setReleasedBefore);
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 boolean getFilteredHandsEnabled(){ public boolean getFilteredHandsEnabled(){

View File

@@ -534,12 +534,21 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
/* Get Card from Edition using the default `CardArtPreference` /* Get Card from Edition using the default `CardArtPreference`
NOTE: this method has NOT been included in the Interface API refactoring as it 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 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) { public PaperCard getCardFromEditions(final String cardName) {
return this.getCardFromEditions(cardName, this.defaultCardArtPreference); 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 @Override
public PaperCard getCardFromEditions(final String cardName, CardArtPreference artPreference) { public PaperCard getCardFromEditions(final String cardName, CardArtPreference artPreference) {
return getCardFromEditions(cardName, artPreference, IPaperCard.NO_ART_INDEX, null); 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() { private void convertByXitaxMethod() {
Date dateWithAllCards = StaticData.instance().getEditions().getEarliestDateWithAllCards(getAllCardsInASinglePool()); Date dateWithAllCards = StaticData.instance().getEditions().getEarliestDateWithAllCards(getAllCardsInASinglePool());
String artOption = StaticData.instance().getPreferredCardArt();
for(Entry<DeckSection, CardPool> p : parts.entrySet()) { for(Entry<DeckSection, CardPool> p : parts.entrySet()) {
if( p.getKey() == DeckSection.Planes || p.getKey() == DeckSection.Schemes || p.getKey() == DeckSection.Avatar) if( p.getKey() == DeckSection.Planes || p.getKey() == DeckSection.Schemes || p.getKey() == DeckSection.Avatar)
continue; continue;
@@ -265,16 +263,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
int count = cp.getValue(); int count = cp.getValue();
PaperCard replacementCard; PaperCard replacementCard;
switch (artOption) { replacementCard = StaticData.instance().getReplacementCard(card, dateWithAllCards);
case "Latest":
replacementCard = StaticData.instance().getCardFromLatestorEarliest(card);
break;
case "Earliest":
replacementCard = StaticData.instance().getCardFromEarliestCoreExp(card);
break;
default:
replacementCard = StaticData.instance().getCardByEditionDate(card, dateWithAllCards);
}
// Note @leriomaggio: The following logic is very obscure to me // 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? // Why looking for a replacement Card and then not using adding it to the pool?