From 0c813024d29d4f73d8aabcd1fee6bee4eb0a7ba0 Mon Sep 17 00:00:00 2001 From: leriomaggio Date: Wed, 9 Jun 2021 18:51:08 +0100 Subject: [PATCH] First improvement to API in convertXitaxMethod simplifying implementation thanks to new CardDb API --- .../src/main/java/forge/StaticData.java | 88 +------------------ .../src/main/java/forge/card/CardDb.java | 11 ++- forge-core/src/main/java/forge/deck/Deck.java | 13 +-- 3 files changed, 15 insertions(+), 97 deletions(-) diff --git a/forge-core/src/main/java/forge/StaticData.java b/forge-core/src/main/java/forge/StaticData.java index 625a04c23e3..07bf0d568ff 100644 --- a/forge-core/src/main/java/forge/StaticData.java +++ b/forge-core/src/main/java/forge/StaticData.java @@ -279,94 +279,14 @@ public class StaticData { public Predicate 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(){ diff --git a/forge-core/src/main/java/forge/card/CardDb.java b/forge-core/src/main/java/forge/card/CardDb.java index 969c3d91b73..819fbc7db1d 100644 --- a/forge-core/src/main/java/forge/card/CardDb.java +++ b/forge-core/src/main/java/forge/card/CardDb.java @@ -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); diff --git a/forge-core/src/main/java/forge/deck/Deck.java b/forge-core/src/main/java/forge/deck/Deck.java index 56810dccd85..246547b08ae 100644 --- a/forge-core/src/main/java/forge/deck/Deck.java +++ b/forge-core/src/main/java/forge/deck/Deck.java @@ -252,8 +252,6 @@ public class Deck extends DeckBase implements Iterable 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