mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Updates to DeckRecognizer (& tests) by using the new methods from StaticData
(Any reference to CardDb has been dropped, along with corresponding card fetching methods). Signed-off-by: leriomaggio <valeriomaggio@gmail.com>
This commit is contained in:
@@ -17,14 +17,13 @@
|
||||
*/
|
||||
package forge.deck;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import forge.StaticData;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardType;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.PaperCard;
|
||||
import forge.util.TextUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
@@ -148,6 +147,34 @@ public class DeckRecognizer {
|
||||
this.type == TokenType.ILLEGAL_CARD_REQUEST ||
|
||||
this.type == TokenType.INVALID_CARD_REQUEST );
|
||||
}
|
||||
|
||||
public String getKey(){
|
||||
if (this.isCardToken())
|
||||
return String.format("%s-%s-%s-%s-%s",
|
||||
this.card.getName(), this.card.getEdition(),
|
||||
this.card.getCollectorNumber(),
|
||||
this.tokenSection.name(), this.getType().name().toLowerCase());
|
||||
return "";
|
||||
}
|
||||
|
||||
public static class TokenKey {
|
||||
public String cardName;
|
||||
public String setCode;
|
||||
public String collectorNumber;
|
||||
public String deckSection;
|
||||
public String typeName;
|
||||
}
|
||||
|
||||
public static TokenKey parseTokenKey(String key){
|
||||
String[] keyInfo = TextUtil.split(key, '-');
|
||||
TokenKey tokenKey = new TokenKey();
|
||||
tokenKey.cardName = keyInfo[0];
|
||||
tokenKey.setCode = keyInfo[1];
|
||||
tokenKey.collectorNumber = keyInfo[2];
|
||||
tokenKey.deckSection = keyInfo[3];
|
||||
tokenKey.typeName = keyInfo[4];
|
||||
return tokenKey;
|
||||
}
|
||||
}
|
||||
|
||||
// Utility Constants
|
||||
@@ -250,18 +277,11 @@ public class DeckRecognizer {
|
||||
return cardTypesList.toArray(new CharSequence[0]);
|
||||
}
|
||||
|
||||
private final CardDb db;
|
||||
private final CardDb altDb;
|
||||
private Date releaseDateConstraint = null;
|
||||
// This two parameters are controlled only via setter methods
|
||||
private List<String> allowedSetCodes = null; // as imposed by current format
|
||||
private DeckFormat deckFormat = null; //
|
||||
|
||||
public DeckRecognizer(CardDb db, CardDb altDb) {
|
||||
this.db = db;
|
||||
this.altDb = altDb;
|
||||
}
|
||||
|
||||
public Token recognizeLine(final String rawLine, DeckSection referenceSection) {
|
||||
if (rawLine == null)
|
||||
return null;
|
||||
@@ -307,6 +327,7 @@ public class DeckRecognizer {
|
||||
public Token recogniseCardToken(final String text, final DeckSection referenceSection) {
|
||||
String line = text.trim();
|
||||
Token uknonwnCardToken = null;
|
||||
StaticData data = StaticData.instance();
|
||||
List<Matcher> cardMatchers = getRegExMatchers(line);
|
||||
for (Matcher matcher : cardMatchers) {
|
||||
String cardName = getRexGroup(matcher, REGRP_CARD);
|
||||
@@ -314,16 +335,16 @@ public class DeckRecognizer {
|
||||
continue;
|
||||
cardName = cardName.trim();
|
||||
//Avoid hit the DB - check whether cardName is contained in the DB
|
||||
CardDb.CardRequest cr = CardDb.CardRequest.fromString(cardName.trim()); // to account for any FOIL request
|
||||
if (!foundInCardDb(cr.cardName))
|
||||
if (!data.isMTGCard(cardName))
|
||||
continue; // skip to the next matcher!
|
||||
String ccount = getRexGroup(matcher, REGRP_CARDNO);
|
||||
String setCode = getRexGroup(matcher, REGRP_SET);
|
||||
String collNo = getRexGroup(matcher, REGRP_COLLNR);
|
||||
String foilGr = getRexGroup(matcher, REGRP_FOIL_GFISH);
|
||||
String deckSec = getRexGroup(matcher, REGRP_DECK_SEC_XMAGE_STYLE);
|
||||
boolean isFoil = false;
|
||||
if (foilGr != null)
|
||||
cr.isFoil = true;
|
||||
isFoil = true;
|
||||
int cardCount = ccount != null ? Integer.parseInt(ccount) : 1;
|
||||
// if any, it will be tried to convert specific collector number to art index (useful for lands).
|
||||
String collectorNumber = collNo != null ? collNo : IPaperCard.NO_COLLECTOR_NUMBER;
|
||||
@@ -346,7 +367,7 @@ public class DeckRecognizer {
|
||||
// we now name is ok, set is ok - we just need to be sure about collector number (if any)
|
||||
// and if that card can be actually found in the requested set.
|
||||
// IOW: we should account for wrong request, e.g. Counterspell|FEM - just doesn't exist!
|
||||
PaperCard pc = this.getCardFromSet(cr.cardName, edition, collectorNumber, artIndex, cr.isFoil);
|
||||
PaperCard pc = data.getCardFromSet(cardName, edition, collectorNumber, artIndex, isFoil);
|
||||
if (pc != null) {
|
||||
// ok so the card has been found - let's see if there's any restriction on the set
|
||||
if (isIllegalSetInGameFormat(edition.getCode()) || isIllegalCardInDeckFormat(pc))
|
||||
@@ -366,11 +387,12 @@ public class DeckRecognizer {
|
||||
// unless it is illegal for current format or invalid with selected date.
|
||||
PaperCard pc = null;
|
||||
if (hasGameFormatConstraints()) {
|
||||
Predicate<PaperCard> filter = (Predicate<PaperCard>) this.db.isLegal(this.allowedSetCodes);
|
||||
pc = this.getCardFromSupportedEditions(cr.cardName, cr.isFoil, filter);
|
||||
pc = data.getCardFromSupportedEditions(cardName, isFoil, this.allowedSetCodes,
|
||||
this.releaseDateConstraint);
|
||||
}
|
||||
if (pc == null)
|
||||
pc = this.getCardFromSupportedEditions(cr.cardName, cr.isFoil, null);
|
||||
pc = data.getCardFromSupportedEditions(cardName, isFoil, null,
|
||||
this.releaseDateConstraint);
|
||||
|
||||
if (pc != null) {
|
||||
if (isIllegalSetInGameFormat(pc.getEdition()) || isIllegalCardInDeckFormat(pc))
|
||||
@@ -425,10 +447,6 @@ public class DeckRecognizer {
|
||||
return this.releaseDateConstraint != null && edition.getDate().compareTo(this.releaseDateConstraint) >= 0;
|
||||
}
|
||||
|
||||
private boolean foundInCardDb(String cardName){
|
||||
return this.db.contains(cardName) || this.altDb.contains(cardName);
|
||||
}
|
||||
|
||||
private List<Matcher> getRegExMatchers(String line) {
|
||||
List<Matcher> matchers = new ArrayList<>();
|
||||
Pattern[] patternsWithCollNumber = new Pattern[] {
|
||||
@@ -456,50 +474,6 @@ public class DeckRecognizer {
|
||||
return matchers;
|
||||
}
|
||||
|
||||
private PaperCard getCardFromSet(final String cardName, final CardEdition edition,
|
||||
final String collectorNumber, final int artIndex,
|
||||
final boolean isFoil) {
|
||||
CardDb targetDb = this.db.contains(cardName) ? this.db : this.altDb;
|
||||
// Try with collector number first
|
||||
PaperCard result = targetDb.getCardFromSet(cardName, edition, collectorNumber, isFoil);
|
||||
if (result == null && !collectorNumber.equals(IPaperCard.NO_COLLECTOR_NUMBER)) {
|
||||
if (artIndex != IPaperCard.NO_ART_INDEX) {
|
||||
// So here we know cardName exists (checked before invoking this method)
|
||||
// and also a Collector Number was specified.
|
||||
// The only case we would reach this point is either due to a wrong edition-card match
|
||||
// (later resulting in Unknown card - e.g. "Counterspell|FEM") or due to the fact that
|
||||
// art Index was specified instead of collector number! Let's give it a go with that
|
||||
// but only if artIndex is not NO_ART_INDEX (e.g. collectorNumber = "*32")
|
||||
int maxArtForCard = targetDb.getMaxArtIndex(cardName);
|
||||
if (artIndex <= maxArtForCard) {
|
||||
// if collNr was "78", it's hardly an artIndex. It was just the wrong collNr for the requested card
|
||||
result = targetDb.getCardFromSet(cardName, edition, artIndex, isFoil);
|
||||
}
|
||||
}
|
||||
if (result == null){
|
||||
// Last chance, try without collector number and see if any match is found
|
||||
result = targetDb.getCardFromSet(cardName, edition, isFoil);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private PaperCard getCardFromSupportedEditions(final String cardName, boolean isFoil,
|
||||
Predicate<PaperCard> filter){
|
||||
String reqInfo = CardDb.CardRequest.compose(cardName, isFoil);
|
||||
CardDb targetDb = this.db.contains(cardName) ? this.db : this.altDb;
|
||||
PaperCard result;
|
||||
if (this.releaseDateConstraint != null) {
|
||||
result = targetDb.getCardFromEditionsReleasedBefore(reqInfo,
|
||||
this.releaseDateConstraint, filter);
|
||||
if (result == null)
|
||||
result = targetDb.getCardFromEditions(reqInfo, filter);
|
||||
}
|
||||
else
|
||||
result = targetDb.getCardFromEditions(reqInfo, filter);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Token recogniseNonCardToken(final String text) {
|
||||
if (isDeckSectionName(text)) {
|
||||
String tokenText = nonCardTokenMatch(text);
|
||||
|
||||
@@ -301,10 +301,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
* =============================
|
||||
*/
|
||||
@Test void testMatchNonCardLine(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
// Test Token Types
|
||||
Token t = recognizer.recogniseNonCardToken("//Lands");
|
||||
@@ -923,7 +920,6 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
assertFalse(matcher.matches());
|
||||
|
||||
foilRequest = "4 Aspect of Hydra [BNG] 117 (F)";
|
||||
target = DeckRecognizer.CARD_SET_COLLNO_PATTERN;
|
||||
matcher = target.matcher(foilRequest);
|
||||
assertTrue(matcher.matches());
|
||||
assertEquals(matcher.group(DeckRecognizer.REGRP_CARDNO), "4");
|
||||
@@ -939,7 +935,6 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
assertFalse(matcher.matches());
|
||||
|
||||
foilRequest = "4 [BNG] Aspect of Hydra 117 (F)";
|
||||
target = DeckRecognizer.SET_CARD_COLLNO_PATTERN;
|
||||
matcher = target.matcher(foilRequest);
|
||||
assertTrue(matcher.matches());
|
||||
assertEquals(matcher.group(DeckRecognizer.REGRP_CARDNO), "4");
|
||||
@@ -979,10 +974,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testRecogniseCardToken(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
String lineRequest = "4x Power Sink+ (TMP) 78";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1071,7 +1063,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
assertEquals(tokenCard.getCollectorNumber(), "78");
|
||||
|
||||
// Relax Set Preference
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
|
||||
lineRequest = "4x Power Sink";
|
||||
cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1097,10 +1089,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testRecognisingCardFromSetUsingAlternateCode(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
String lineRequest = "4x Power Sink+ TE 78";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1119,10 +1108,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testSingleWordCardNameMatchesCorrectly(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
String lineRequest = "2x Counterspell ICE";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1135,7 +1121,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
assertEquals(tokenCard.getEdition(), "ICE");
|
||||
|
||||
// Remove Set code
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
lineRequest = "2x Counterspell";
|
||||
cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
assertNotNull(cardToken);
|
||||
@@ -1149,10 +1135,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testPassingInArtIndexRatherThanCollectorNumber(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
String lineRequest = "20x Mountain MIR 3";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1168,10 +1151,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testCollectorNumberIsNotConfusedAsArtIndexInstead(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
String lineRequest = "2x Auspicious Ancestor MIR 3";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1187,10 +1167,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testCardRequestWithWrongCollectorNumberStillReturnsTheCardFromSetIfAny(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
String requestLine = "3 Jayemdae Tome (LEB) 231"; // actually found in TappedOut Deck Export
|
||||
// NOTE: Expected Coll Nr should be 255
|
||||
@@ -1214,10 +1191,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testRequestingCardFromTheWrongSetReturnsUnknownCard(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
String lineRequest = "2x Counterspell FEM";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1227,10 +1201,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testRequestingCardFromNonExistingSetReturnsUnknownCard(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
String lineRequest = "2x Counterspell BOU";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1241,10 +1212,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testRequestingCardWithRestrictionsOnSetsFromGameFormat(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
// Setting Fantasy Constructed Game Format: Urza's Block Format
|
||||
List<String> allowedSets = Arrays.asList("USG", "ULG", "UDS", "PUDS", "PULG", "PUSG");
|
||||
recognizer.setGameFormatConstraint(allowedSets);
|
||||
@@ -1265,10 +1233,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testRequestingCardWithRestrictionsOnDeckFormat(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
String lineRequest = "Ancestral Recall";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1278,7 +1243,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
PaperCard ancestralCard = cardToken.getCard();
|
||||
assertEquals(cardToken.getNumber(), 1);
|
||||
assertEquals(ancestralCard.getName(), "Ancestral Recall");
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(ancestralCard.getEdition(), "VMA");
|
||||
|
||||
recognizer.setDeckFormatConstraint(DeckFormat.TinyLeaders);
|
||||
@@ -1289,12 +1254,9 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testRequestingCardWithReleaseDateConstraints(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
recognizer.setDateConstraint(2002, 1);
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
|
||||
String lineRequest = "Ancestral Recall";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1304,7 +1266,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
PaperCard ancestralCard = cardToken.getCard();
|
||||
assertEquals(cardToken.getNumber(), 1);
|
||||
assertEquals(ancestralCard.getName(), "Ancestral Recall");
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(ancestralCard.getEdition(), "2ED");
|
||||
|
||||
// Counterspell editions
|
||||
@@ -1321,12 +1283,9 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testInvalidCardRequestWhenReleaseDateConstraintsAreUp(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
|
||||
// First run without constraint to check that it's a valid request
|
||||
String lineRequest = "Counterspell|MH2";
|
||||
@@ -1347,13 +1306,10 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testCardMatchWithDateANDGameFormatConstraints(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
// Baseline - no constraints
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
String lineRequest = "2x Lightning Dragon";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
assertNotNull(cardToken);
|
||||
@@ -1442,13 +1398,10 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testCardMatchWithDateANDdeckFormatConstraints(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
// Baseline - no constraints
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
|
||||
String lineRequest = "Flash";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1490,13 +1443,10 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testCardMatchWithGameANDdeckFormatConstraints(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
// Baseline - no constraints
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
|
||||
String lineRequest = "Flash";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1555,13 +1505,10 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testCardMatchWitDateANDgameANDdeckFormatConstraints(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
// Baseline - no constraints
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
|
||||
String lineRequest = "Flash";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1670,11 +1617,8 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testCardRecognisedMTGGoldfishFormat(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
|
||||
String lineRequest = "4 Aspect of Hydra [BNG] (F)";
|
||||
Token cardToken = recognizer.recogniseCardToken(lineRequest, null);
|
||||
@@ -1711,11 +1655,8 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testCardNameEntryInMarkDownExportFromTappedOut(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
|
||||
String line = "* 1 [Ancestral Recall](http://tappedout.nethttp://tappedout.net/mtg-card/ancestral-recall/)";
|
||||
|
||||
@@ -1769,10 +1710,7 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
}
|
||||
|
||||
@Test void testRecognizeCardTokenInXMageFormatRequest(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
String xmageFormatRequest = "1 [LRW:51] Amoeboid Changeling";
|
||||
Token xmageCardToken = recognizer.recogniseCardToken(xmageFormatRequest, null);
|
||||
@@ -1791,12 +1729,9 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
||||
* ===================================
|
||||
*/
|
||||
@Test void testRecognizeLines(){
|
||||
StaticData magicDb = FModel.getMagicDb();
|
||||
CardDb db = magicDb.getCommonCards();
|
||||
CardDb altDb = magicDb.getVariantCards();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(db, altDb);
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
|
||||
assertEquals(db.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
assertEquals(StaticData.instance().getCommonCards().getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
|
||||
|
||||
String lineRequest = "// MainBoard";
|
||||
Token token = recognizer.recognizeLine(lineRequest, null);
|
||||
|
||||
@@ -11,7 +11,6 @@ import forge.gui.interfaces.ICheckBox;
|
||||
import forge.gui.interfaces.IComboBox;
|
||||
import forge.gui.util.SOptionPane;
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.util.Localizer;
|
||||
|
||||
public class DeckImportController {
|
||||
@@ -77,8 +76,7 @@ public class DeckImportController {
|
||||
|
||||
public List<DeckRecognizer.Token> parseInput(String input) {
|
||||
tokens.clear();
|
||||
DeckRecognizer recognizer = new DeckRecognizer(FModel.getMagicDb().getCommonCards(),
|
||||
FModel.getMagicDb().getVariantCards());
|
||||
DeckRecognizer recognizer = new DeckRecognizer();
|
||||
if (dateTimeCheck.isSelected()) {
|
||||
recognizer.setDateConstraint(yearDropdown.getSelectedItem(), monthDropdown.getSelectedIndex());
|
||||
}
|
||||
@@ -94,7 +92,7 @@ public class DeckImportController {
|
||||
if (token != null) {
|
||||
if (token.getType() == DeckRecognizer.TokenType.DECK_SECTION_NAME)
|
||||
referenceDeckSectionInParsing = DeckSection.valueOf(token.getText());
|
||||
else if (token.isCardToken()) {
|
||||
else if (token.getType() == DeckRecognizer.TokenType.LEGAL_CARD_REQUEST) {
|
||||
DeckSection tokenSection = token.getTokenSection();
|
||||
if (!tokenSection.equals(referenceDeckSectionInParsing)) {
|
||||
DeckRecognizer.Token sectionToken = DeckRecognizer.Token.DeckSection(token.getTokenSection().name());
|
||||
@@ -105,7 +103,10 @@ public class DeckImportController {
|
||||
referenceDeckSectionInParsing = tokenSection;
|
||||
}
|
||||
}
|
||||
tokens.add(token); // add found token
|
||||
if (token.getType() == DeckRecognizer.TokenType.DECK_NAME)
|
||||
tokens.add(0, token); // always add deck name top of the decklist
|
||||
else
|
||||
tokens.add(token);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user