|
5 | 5 | import com.google.common.collect.Maps; |
6 | 6 | import com.google.common.collect.Multimap; |
7 | 7 |
|
| 8 | +import forge.StaticData; |
8 | 9 | import forge.card.CardDb; |
9 | 10 | import forge.card.CardEdition; |
10 | 11 | import forge.card.CardRules; |
11 | 12 | import forge.item.IPaperCard; |
12 | 13 | import forge.item.PaperToken; |
13 | 14 | import forge.util.Aggregates; |
| 15 | +import org.apache.commons.lang3.function.Predicates; |
14 | 16 |
|
15 | 17 | import java.util.*; |
16 | 18 | import java.util.function.Predicate; |
@@ -103,32 +105,35 @@ protected PaperToken fallbackToken(String name, CardEdition realEdition) { |
103 | 105 |
|
104 | 106 | // Find latest token before release of original card, or earliest after that |
105 | 107 | private PaperToken smartFallbackToken(String name, CardEdition realEdition) { |
106 | | - PaperToken coreExpansionReprintToken = smartFallbackToken(name, realEdition, true); |
107 | | - return coreExpansionReprintToken != null ? coreExpansionReprintToken : smartFallbackToken(name, realEdition, false); |
| 108 | + |
| 109 | + final EnumSet<CardEdition.Type> specialEditions = EnumSet.of(CardEdition.Type.FUNNY, CardEdition.Type.ONLINE, CardEdition.Type.OTHER); |
| 110 | + specialEditions.remove(realEdition.getType()); |
| 111 | + CardDb.CardArtPreference artPreference = StaticData.instance().getCardArtPreference(); |
| 112 | + |
| 113 | + PaperToken paperToken = smartFallbackToken(name, realEdition, Predicate.<CardEdition>not( |
| 114 | + edition -> specialEditions.contains(edition.getType())).and(artPreference::accept)); |
| 115 | + return paperToken != null ? paperToken : smartFallbackToken(name, realEdition, Predicates.falsePredicate()); |
108 | 116 | } |
109 | 117 |
|
110 | | - private PaperToken smartFallbackToken(String name, CardEdition realEdition, boolean onlyCoreExpansionOrReprint) { |
111 | | - String latestFound = null; |
112 | | - boolean pastRealEdition = false; |
113 | | - final EnumSet<CardEdition.Type> coreExpansionOrReprint = EnumSet.of(CardEdition.Type.CORE, CardEdition.Type.EXPANSION); |
114 | | - coreExpansionOrReprint.addAll(CardEdition.Type.REPRINT_SET_TYPES); |
| 118 | + private PaperToken smartFallbackToken(String name, CardEdition realEdition, Predicate<CardEdition> eligible) { |
| 119 | + String lastMatchedKey = null; |
| 120 | + boolean reachedRealEdition = false; |
115 | 121 | for (CardEdition edition : this.editions.getOrderedEditions(false)) { |
116 | 122 | if (edition.equals(realEdition)) { |
117 | | - pastRealEdition = true; |
| 123 | + reachedRealEdition = true; |
118 | 124 | } |
119 | | - if (onlyCoreExpansionOrReprint && !coreExpansionOrReprint.contains(edition.getType())) { |
120 | | - // Core, Expansion and Reprint sets are more likely to have available token images |
| 125 | + if (!eligible.test(edition)) { |
121 | 126 | continue; |
122 | 127 | } |
123 | 128 | String fullName = String.format("%s_%s", name, edition.getCode().toLowerCase()); |
124 | 129 | if (loadTokenFromSet(edition, name)) { |
125 | | - latestFound = fullName; |
| 130 | + lastMatchedKey = fullName; |
126 | 131 | } |
127 | | - if (pastRealEdition && latestFound != null) { |
| 132 | + if (reachedRealEdition && lastMatchedKey != null) { |
128 | 133 | break; |
129 | 134 | } |
130 | 135 | } |
131 | | - return latestFound != null ? Aggregates.random(allTokenByName.get(latestFound)) : null; |
| 136 | + return lastMatchedKey != null ? Aggregates.random(allTokenByName.get(lastMatchedKey)) : null; |
132 | 137 | } |
133 | 138 |
|
134 | 139 | @Override |
|
0 commit comments