mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Improved support for Unknown cards in DeckImport
DeckImport now avoids including non-deck and metadata info in decklist as UnknownText, whilst any line that looks like a card request (i.e. includes a card quantity in the beginning) is interpreted as Unknown card. This seems a good compromise with showing typo and any mispelling in card list whilst avoiding flooding decklist with unnecessary info.
This commit is contained in:
@@ -584,7 +584,7 @@ public class DeckRecognizer {
|
|||||||
|
|
||||||
public Token recogniseCardToken(final String text, final DeckSection currentDeckSection) {
|
public Token recogniseCardToken(final String text, final DeckSection currentDeckSection) {
|
||||||
String line = text.trim();
|
String line = text.trim();
|
||||||
Token uknonwnCardToken = null;
|
Token unknownCardToken = null;
|
||||||
StaticData data = StaticData.instance();
|
StaticData data = StaticData.instance();
|
||||||
List<Matcher> cardMatchers = getRegExMatchers(line);
|
List<Matcher> cardMatchers = getRegExMatchers(line);
|
||||||
for (Matcher matcher : cardMatchers) {
|
for (Matcher matcher : cardMatchers) {
|
||||||
@@ -596,10 +596,7 @@ public class DeckRecognizer {
|
|||||||
if (!data.isMTGCard(cardName)){
|
if (!data.isMTGCard(cardName)){
|
||||||
// check the case for double-sided cards
|
// check the case for double-sided cards
|
||||||
cardName = checkDoubleSidedCard(cardName);
|
cardName = checkDoubleSidedCard(cardName);
|
||||||
if (cardName == null)
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String ccount = getRexGroup(matcher, REGRP_CARDNO);
|
String ccount = getRexGroup(matcher, REGRP_CARDNO);
|
||||||
String setCode = getRexGroup(matcher, REGRP_SET);
|
String setCode = getRexGroup(matcher, REGRP_SET);
|
||||||
String collNo = getRexGroup(matcher, REGRP_COLLNR);
|
String collNo = getRexGroup(matcher, REGRP_COLLNR);
|
||||||
@@ -607,6 +604,14 @@ public class DeckRecognizer {
|
|||||||
String deckSecFromCardLine = getRexGroup(matcher, REGRP_DECK_SEC_XMAGE_STYLE);
|
String deckSecFromCardLine = getRexGroup(matcher, REGRP_DECK_SEC_XMAGE_STYLE);
|
||||||
boolean isFoil = foilGr != null;
|
boolean isFoil = foilGr != null;
|
||||||
int cardCount = ccount != null ? Integer.parseInt(ccount) : 1;
|
int cardCount = ccount != null ? Integer.parseInt(ccount) : 1;
|
||||||
|
|
||||||
|
if (cardName == null){
|
||||||
|
if (ccount != null)
|
||||||
|
// setting cardCount to zero as the text is the whole line
|
||||||
|
unknownCardToken = Token.UnknownCard(text, null, 0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// if any, it will be tried to convert specific collector number to art index (useful for lands).
|
// 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;
|
String collectorNumber = collNo != null ? collNo : IPaperCard.NO_COLLECTOR_NUMBER;
|
||||||
int artIndex;
|
int artIndex;
|
||||||
@@ -620,7 +625,7 @@ public class DeckRecognizer {
|
|||||||
CardEdition edition = StaticData.instance().getEditions().get(setCode);
|
CardEdition edition = StaticData.instance().getEditions().get(setCode);
|
||||||
if (edition == null) {
|
if (edition == null) {
|
||||||
// set the case for unknown card (in case) and continue to the next for any better matching
|
// set the case for unknown card (in case) and continue to the next for any better matching
|
||||||
uknonwnCardToken = Token.UnknownCard(cardName, setCode, cardCount);
|
unknownCardToken = Token.UnknownCard(cardName, setCode, cardCount);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -652,7 +657,7 @@ public class DeckRecognizer {
|
|||||||
return checkAndSetCardToken(pc, edition, cardCount, deckSecFromCardLine, currentDeckSection);
|
return checkAndSetCardToken(pc, edition, cardCount, deckSecFromCardLine, currentDeckSection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return uknonwnCardToken; // either null or unknown card
|
return unknownCardToken; // either null or unknown card
|
||||||
}
|
}
|
||||||
|
|
||||||
private String checkDoubleSidedCard(final String cardName){
|
private String checkDoubleSidedCard(final String cardName){
|
||||||
|
|||||||
@@ -758,7 +758,8 @@ public class DeckImport<TModel extends DeckBase> extends FDialog {
|
|||||||
// Card Warning Msgs
|
// Card Warning Msgs
|
||||||
case UNKNOWN_CARD:
|
case UNKNOWN_CARD:
|
||||||
case UNSUPPORTED_CARD:
|
case UNSUPPORTED_CARD:
|
||||||
return String.format("%s x %s", token.getQuantity(), token.getText());
|
return token.getQuantity() > 0 ? String.format("%s x %s", token.getQuantity(), token.getText())
|
||||||
|
: token.getText();
|
||||||
|
|
||||||
case UNSUPPORTED_DECK_SECTION:
|
case UNSUPPORTED_DECK_SECTION:
|
||||||
return String.format("%s: %s", Localizer.getInstance().getMessage("lblWarningMsgPrefix"),
|
return String.format("%s: %s", Localizer.getInstance().getMessage("lblWarningMsgPrefix"),
|
||||||
@@ -784,12 +785,13 @@ public class DeckImport<TModel extends DeckBase> extends FDialog {
|
|||||||
case CARD_CMC:
|
case CARD_CMC:
|
||||||
case MANA_COLOUR:
|
case MANA_COLOUR:
|
||||||
case COMMENT:
|
case COMMENT:
|
||||||
case UNKNOWN_TEXT:
|
|
||||||
return token.getText();
|
return token.getText();
|
||||||
|
|
||||||
case DECK_NAME:
|
case DECK_NAME:
|
||||||
return String.format("%s: %s", Localizer.getInstance().getMessage("lblDeckName"),
|
return String.format("%s: %s", Localizer.getInstance().getMessage("lblDeckName"),
|
||||||
token.getText());
|
token.getText());
|
||||||
|
|
||||||
|
case UNKNOWN_TEXT:
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -815,8 +817,6 @@ public class DeckImport<TModel extends DeckBase> extends FDialog {
|
|||||||
case UNSUPPORTED_CARD:
|
case UNSUPPORTED_CARD:
|
||||||
return Localizer.getInstance().getMessage("lblErrUnsupportedCard", this.currentGameType);
|
return Localizer.getInstance().getMessage("lblErrUnsupportedCard", this.currentGameType);
|
||||||
|
|
||||||
case UNKNOWN_TEXT:
|
|
||||||
return Localizer.getInstance().getMessage("lblWarnUnknownTxtMsg");
|
|
||||||
case UNKNOWN_CARD:
|
case UNKNOWN_CARD:
|
||||||
return String.format("%s: %s", Localizer.getInstance().getMessage("lblWarningMsgPrefix"),
|
return String.format("%s: %s", Localizer.getInstance().getMessage("lblWarningMsgPrefix"),
|
||||||
Localizer.getInstance().getMessage("lblWarnUnknownCardMsg"));
|
Localizer.getInstance().getMessage("lblWarnUnknownCardMsg"));
|
||||||
@@ -831,6 +831,7 @@ public class DeckImport<TModel extends DeckBase> extends FDialog {
|
|||||||
case CARD_RARITY:
|
case CARD_RARITY:
|
||||||
case DECK_NAME:
|
case DECK_NAME:
|
||||||
case LEGAL_CARD:
|
case LEGAL_CARD:
|
||||||
|
case UNKNOWN_TEXT:
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -848,10 +849,10 @@ public class DeckImport<TModel extends DeckBase> extends FDialog {
|
|||||||
case CARD_FROM_INVALID_SET:
|
case CARD_FROM_INVALID_SET:
|
||||||
case UNSUPPORTED_CARD:
|
case UNSUPPORTED_CARD:
|
||||||
return KO_NOIMPORT_CLASS;
|
return KO_NOIMPORT_CLASS;
|
||||||
case UNKNOWN_CARD:
|
|
||||||
case UNSUPPORTED_DECK_SECTION:
|
case UNSUPPORTED_DECK_SECTION:
|
||||||
case WARNING_MESSAGE:
|
case WARNING_MESSAGE:
|
||||||
case UNKNOWN_TEXT:
|
case UNKNOWN_CARD:
|
||||||
|
return WARN_MSG_CLASS;
|
||||||
case COMMENT:
|
case COMMENT:
|
||||||
return COMMENT_CLASS;
|
return COMMENT_CLASS;
|
||||||
case DECK_NAME:
|
case DECK_NAME:
|
||||||
@@ -865,6 +866,7 @@ public class DeckImport<TModel extends DeckBase> extends FDialog {
|
|||||||
case CARD_CMC:
|
case CARD_CMC:
|
||||||
case MANA_COLOUR:
|
case MANA_COLOUR:
|
||||||
return CMC_CLASS;
|
return CMC_CLASS;
|
||||||
|
case UNKNOWN_TEXT:
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2486,9 +2486,64 @@ public class DeckRecognizerTest extends ForgeCardMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*=================================
|
/*=================================
|
||||||
* TEST BANNED
|
* TEST UNKNOWN CARDS
|
||||||
* ================================ */
|
* ================================ */
|
||||||
|
|
||||||
|
@Test void testUknonwCardIsReturnedForAnExistingCardFromTheWrongSet(){
|
||||||
|
String cardRequest = "Counterspell FEM";
|
||||||
|
DeckRecognizer recognizer = new DeckRecognizer();
|
||||||
|
Token unknonwCardToken = recognizer.recogniseCardToken(cardRequest, null);
|
||||||
|
assertNotNull(unknonwCardToken);
|
||||||
|
assertEquals(unknonwCardToken.getType(), TokenType.UNKNOWN_CARD);
|
||||||
|
assertNull(unknonwCardToken.getCard());
|
||||||
|
assertNull(unknonwCardToken.getTokenSection());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void testUknownCardIsReturnedForLineRequestsThatLooksLikeACardButAreNotSupported(){
|
||||||
|
String cardRequest = "2x Counterspelling TMP";
|
||||||
|
DeckRecognizer recognizer = new DeckRecognizer();
|
||||||
|
Token unknonwCardToken = recognizer.recogniseCardToken(cardRequest, null);
|
||||||
|
assertNotNull(unknonwCardToken);
|
||||||
|
assertEquals(unknonwCardToken.getType(), TokenType.UNKNOWN_CARD);
|
||||||
|
assertNull(unknonwCardToken.getCard());
|
||||||
|
assertNull(unknonwCardToken.getTokenSection());
|
||||||
|
|
||||||
|
cardRequest = "2x Counterspelling";
|
||||||
|
unknonwCardToken = recognizer.recogniseCardToken(cardRequest, null);
|
||||||
|
assertNotNull(unknonwCardToken);
|
||||||
|
assertEquals(unknonwCardToken.getType(), TokenType.UNKNOWN_CARD);
|
||||||
|
assertNull(unknonwCardToken.getCard());
|
||||||
|
assertNull(unknonwCardToken.getTokenSection());
|
||||||
|
|
||||||
|
cardRequest = "2x Counterspell FEM ";
|
||||||
|
unknonwCardToken = recognizer.recogniseCardToken(cardRequest, null);
|
||||||
|
assertNotNull(unknonwCardToken);
|
||||||
|
assertEquals(unknonwCardToken.getType(), TokenType.UNKNOWN_CARD);
|
||||||
|
assertNull(unknonwCardToken.getCard());
|
||||||
|
assertNull(unknonwCardToken.getTokenSection());
|
||||||
|
|
||||||
|
cardRequest = "SB: 2x Counterspelling TMP"; // adding deck section reference
|
||||||
|
unknonwCardToken = recognizer.recogniseCardToken(cardRequest, null);
|
||||||
|
assertNotNull(unknonwCardToken);
|
||||||
|
assertEquals(unknonwCardToken.getType(), TokenType.UNKNOWN_CARD);
|
||||||
|
assertNull(unknonwCardToken.getCard());
|
||||||
|
assertNull(unknonwCardToken.getTokenSection());
|
||||||
|
|
||||||
|
cardRequest = "SB: 2x Counterspelling TMP (F)"; // adding deck section reference
|
||||||
|
unknonwCardToken = recognizer.recogniseCardToken(cardRequest, null);
|
||||||
|
assertNotNull(unknonwCardToken);
|
||||||
|
assertEquals(unknonwCardToken.getType(), TokenType.UNKNOWN_CARD);
|
||||||
|
assertNull(unknonwCardToken.getCard());
|
||||||
|
assertNull(unknonwCardToken.getTokenSection());
|
||||||
|
|
||||||
|
cardRequest = "SB: 2x Counterspelling+ TMP"; // adding deck section reference
|
||||||
|
unknonwCardToken = recognizer.recogniseCardToken(cardRequest, null);
|
||||||
|
assertNotNull(unknonwCardToken);
|
||||||
|
assertEquals(unknonwCardToken.getType(), TokenType.UNKNOWN_CARD);
|
||||||
|
assertNull(unknonwCardToken.getCard());
|
||||||
|
assertNull(unknonwCardToken.getTokenSection());
|
||||||
|
}
|
||||||
|
|
||||||
/*===============
|
/*===============
|
||||||
* TEST TOKEN-KEY
|
* TEST TOKEN-KEY
|
||||||
* ============== */
|
* ============== */
|
||||||
|
|||||||
@@ -2658,7 +2658,6 @@ lblWarnLimitedCard={0} in {1}
|
|||||||
lblErrCardEditionDate=Set not compliant with Release Date option
|
lblErrCardEditionDate=Set not compliant with Release Date option
|
||||||
lblErrUnsupportedCard=Not allowed in {0}
|
lblErrUnsupportedCard=Not allowed in {0}
|
||||||
lblWarnUnknownCardMsg=Unknown Card or Unsupported in Forge
|
lblWarnUnknownCardMsg=Unknown Card or Unsupported in Forge
|
||||||
lblWarnUnknownTxtMsg=Unrecognized or Unsupported Card or Placeholder
|
|
||||||
lblWarnTooManyCommanders=Current {0} Section contains {1} potential Commander Cards: {2}
|
lblWarnTooManyCommanders=Current {0} Section contains {1} potential Commander Cards: {2}
|
||||||
lblWarnCommandersInSideExtra=Please check and move one to the Commander Section, in case.
|
lblWarnCommandersInSideExtra=Please check and move one to the Commander Section, in case.
|
||||||
lblWarnDeckSectionNotAllowedInEditor={0} Section is not allowed in {1}
|
lblWarnDeckSectionNotAllowedInEditor={0} Section is not allowed in {1}
|
||||||
|
|||||||
@@ -2656,7 +2656,6 @@ lblWarnLimitedCard={0} in {1}
|
|||||||
lblErrCardEditionDate=Set not compliant with Release Date option
|
lblErrCardEditionDate=Set not compliant with Release Date option
|
||||||
lblErrUnsupportedCard=Not allowed in {0}
|
lblErrUnsupportedCard=Not allowed in {0}
|
||||||
lblWarnUnknownCardMsg=Unknown Card or Unsupported in Forge
|
lblWarnUnknownCardMsg=Unknown Card or Unsupported in Forge
|
||||||
lblWarnUnknownTxtMsg=Unrecognized or Unsupported Card or Placeholder
|
|
||||||
lblWarnTooManyCommanders=Current {0} Section contains {1} potential Commander Cards: {2}
|
lblWarnTooManyCommanders=Current {0} Section contains {1} potential Commander Cards: {2}
|
||||||
lblWarnCommandersInSideExtra=Please check and move one to the Commander Section, in case.
|
lblWarnCommandersInSideExtra=Please check and move one to the Commander Section, in case.
|
||||||
lblWarnDeckSectionNotAllowedInEditor={0} Section is not allowed in {1}
|
lblWarnDeckSectionNotAllowedInEditor={0} Section is not allowed in {1}
|
||||||
|
|||||||
@@ -2656,7 +2656,6 @@ lblWarnLimitedCard={0} in {1}
|
|||||||
lblErrCardEditionDate=Set not compliant with Release Date option
|
lblErrCardEditionDate=Set not compliant with Release Date option
|
||||||
lblErrUnsupportedCard=Not allowed in {0}
|
lblErrUnsupportedCard=Not allowed in {0}
|
||||||
lblWarnUnknownCardMsg=Unknown Card or Unsupported in Forge
|
lblWarnUnknownCardMsg=Unknown Card or Unsupported in Forge
|
||||||
lblWarnUnknownTxtMsg=Unrecognized or Unsupported Card or Placeholder
|
|
||||||
lblWarnTooManyCommanders=Current {0} Section contains {1} potential Commander Cards: {2}
|
lblWarnTooManyCommanders=Current {0} Section contains {1} potential Commander Cards: {2}
|
||||||
lblWarnCommandersInSideExtra=Please check and move one to the Commander Section, in case.
|
lblWarnCommandersInSideExtra=Please check and move one to the Commander Section, in case.
|
||||||
lblWarnDeckSectionNotAllowedInEditor={0} Section is not allowed in {1}
|
lblWarnDeckSectionNotAllowedInEditor={0} Section is not allowed in {1}
|
||||||
|
|||||||
@@ -2656,7 +2656,6 @@ lblWarnLimitedCard={0} in {1}
|
|||||||
lblErrCardEditionDate=Edizione non valida secondo l'opzione sulla data di pubblicazione selezionata
|
lblErrCardEditionDate=Edizione non valida secondo l'opzione sulla data di pubblicazione selezionata
|
||||||
lblErrUnsupportedCard=Non Permesso in {0}
|
lblErrUnsupportedCard=Non Permesso in {0}
|
||||||
lblWarnUnknownCardMsg=Carta Sconosciuta, o non supportata in Forge
|
lblWarnUnknownCardMsg=Carta Sconosciuta, o non supportata in Forge
|
||||||
lblWarnUnknownTxtMsg=Carda o Segnaposto non riconosciuto o non supportato
|
|
||||||
lblWarnTooManyCommanders=La Sezione {0} contiene {1} potenziali carte Commander: {2}
|
lblWarnTooManyCommanders=La Sezione {0} contiene {1} potenziali carte Commander: {2}
|
||||||
lblWarnCommandersInSideExtra=Per favore, controlla e nel caso spostane una nella sezione Commander.
|
lblWarnCommandersInSideExtra=Per favore, controlla e nel caso spostane una nella sezione Commander.
|
||||||
lblWarnDeckSectionNotAllowedInEditor={0} Sezione non è permessa in {1}
|
lblWarnDeckSectionNotAllowedInEditor={0} Sezione non è permessa in {1}
|
||||||
|
|||||||
@@ -2655,7 +2655,6 @@ lblWarnLimitedCard={0} in {1}
|
|||||||
lblErrCardEditionDate=Set not compliant with Release Date option
|
lblErrCardEditionDate=Set not compliant with Release Date option
|
||||||
lblErrUnsupportedCard=Not allowed in {0}
|
lblErrUnsupportedCard=Not allowed in {0}
|
||||||
lblWarnUnknownCardMsg=Unknown Card or Unsupported in Forge
|
lblWarnUnknownCardMsg=Unknown Card or Unsupported in Forge
|
||||||
lblWarnUnknownTxtMsg=Unrecognized or Unsupported Card or Placeholder
|
|
||||||
lblWarnTooManyCommanders=Current {0} Section contains {1} potential Commander Cards: {2}
|
lblWarnTooManyCommanders=Current {0} Section contains {1} potential Commander Cards: {2}
|
||||||
lblWarnCommandersInSideExtra=Please check and move one to the Commander Section, in case.
|
lblWarnCommandersInSideExtra=Please check and move one to the Commander Section, in case.
|
||||||
lblWarnDeckSectionNotAllowedInEditor={0} Section is not allowed in {1}
|
lblWarnDeckSectionNotAllowedInEditor={0} Section is not allowed in {1}
|
||||||
|
|||||||
@@ -2657,7 +2657,6 @@ lblWarnLimitedCard={0} in {1}
|
|||||||
lblErrCardEditionDate=Set not compliant with Release Date option
|
lblErrCardEditionDate=Set not compliant with Release Date option
|
||||||
lblErrUnsupportedCard=Not allowed in {0}
|
lblErrUnsupportedCard=Not allowed in {0}
|
||||||
lblWarnUnknownCardMsg=Unknown Card or Unsupported in Forge
|
lblWarnUnknownCardMsg=Unknown Card or Unsupported in Forge
|
||||||
lblWarnUnknownTxtMsg=Unrecognized or Unsupported Card or Placeholder
|
|
||||||
lblWarnTooManyCommanders=Current {0} Section contains {1} potential Commander Cards: {2}
|
lblWarnTooManyCommanders=Current {0} Section contains {1} potential Commander Cards: {2}
|
||||||
lblWarnCommandersInSideExtra=Please check and move one to the Commander Section, in case.
|
lblWarnCommandersInSideExtra=Please check and move one to the Commander Section, in case.
|
||||||
lblWarnDeckSectionNotAllowedInEditor={0} Section is not allowed in {1}
|
lblWarnDeckSectionNotAllowedInEditor={0} Section is not allowed in {1}
|
||||||
|
|||||||
Reference in New Issue
Block a user