mirror of
https://github.com/correl/mage.git
synced 2024-11-21 19:18:40 +00:00
decks: improved deck import to support unicode card names from LTR, UGL and other sets, added verify tests for name converters (closes #10465)
This commit is contained in:
parent
eebb82c591
commit
d91147f01a
3 changed files with 78 additions and 16 deletions
|
@ -65,6 +65,18 @@ public final class MtgJsonCard {
|
|||
return getNameAsFace();
|
||||
}
|
||||
|
||||
return asciiName != null ? asciiName : name;
|
||||
return getNameAsASCII();
|
||||
}
|
||||
|
||||
public String getNameAsUnicode() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getNameAsASCII() {
|
||||
return this.asciiName != null ? this.asciiName : this.name;
|
||||
}
|
||||
|
||||
public boolean isUseUnicodeName() {
|
||||
return this.asciiName != null && this.name != null && !this.asciiName.equals(this.name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import mage.abilities.effects.common.counter.ProliferateEffect;
|
|||
import mage.abilities.effects.keyword.ScryEffect;
|
||||
import mage.abilities.keyword.*;
|
||||
import mage.cards.*;
|
||||
import mage.cards.decks.CardNameUtil;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.cards.decks.importer.DeckImporter;
|
||||
import mage.cards.repository.*;
|
||||
|
@ -2358,4 +2359,41 @@ public class VerifyCardDataTest {
|
|||
Assert.fail("Found " + errorsList.size() + " errors in the cubes, look at logs above for more details");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_checkUnicodeCardNamesForImport() {
|
||||
// deck import can catch real card names with non-ascii symbols like Arwen Undómiel, so it must be able to process it
|
||||
|
||||
// check unicode card
|
||||
MtgJsonCard card = MtgJsonService.cardFromSet("LTR", "Arwen Undomiel", "194");
|
||||
Assert.assertNotNull("test card must exists", card);
|
||||
Assert.assertTrue(card.isUseUnicodeName());
|
||||
Assert.assertEquals("Arwen Undomiel", card.getNameAsASCII());
|
||||
Assert.assertEquals("Arwen Undómiel", card.getNameAsUnicode());
|
||||
Assert.assertEquals("Arwen Undomiel", card.getNameAsFull());
|
||||
|
||||
// mtga format can contain /// in the names, so check it too
|
||||
// see https://github.com/magefree/mage/pull/9855
|
||||
Assert.assertEquals("Dusk // Dawn", CardNameUtil.normalizeCardName("Dusk /// Dawn"));
|
||||
|
||||
// check all converters
|
||||
Collection<String> errorsList = new ArrayList<>();
|
||||
MtgJsonService.sets().values().forEach(jsonSet -> {
|
||||
jsonSet.cards.forEach(jsonCard -> {
|
||||
if (jsonCard.isUseUnicodeName()) {
|
||||
String inName = jsonCard.getNameAsUnicode();
|
||||
String outName = CardNameUtil.normalizeCardName(inName);
|
||||
String needOutName = jsonCard.getNameAsFace();
|
||||
if (!outName.equals(needOutName)) {
|
||||
// how-to fix: add new unicode symbol in CardNameUtil.normalizeCardName
|
||||
errorsList.add(String.format("error, found unsupported unicode symbol in %s - %s", inName, jsonSet.code));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
printMessages(errorsList);
|
||||
if (errorsList.size() > 0) {
|
||||
Assert.fail(String.format("Card name converters contains unsupported unicode symbols in %d cards, see logs above", errorsList.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,22 +6,34 @@ public class CardNameUtil {
|
|||
|
||||
public static final Pattern CARD_NAME_PATTERN = Pattern.compile("[ !\"&',\\-./0-9:A-Za-z]+");
|
||||
|
||||
/**
|
||||
* Convert card names with unicode symbols to ascii, uses to deck import from a third party services
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static String normalizeCardName(String name) {
|
||||
// new symbols checks in verify test, no need to manually search it
|
||||
return name
|
||||
.replace("&", "//")
|
||||
.replace("///", "//")
|
||||
.replace("Æ", "Ae")
|
||||
.replace("ö", "A")
|
||||
.replace("ö", "o")
|
||||
.replace("û", "u")
|
||||
.replace("í", "i")
|
||||
.replace("â", "a")
|
||||
.replace("á", "a")
|
||||
.replace("à", "a")
|
||||
.replace("é", "e")
|
||||
.replace("ú", "u")
|
||||
.replace("†", "+")
|
||||
.replace("★", "*");
|
||||
.replace("&", "//")
|
||||
.replace("///", "//")
|
||||
.replace("Æ", "Ae")
|
||||
.replace("ö", "A")
|
||||
.replace("ö", "o")
|
||||
.replace("û", "u")
|
||||
.replace("í", "i")
|
||||
.replace("â", "a")
|
||||
.replace("á", "a")
|
||||
.replace("à", "a")
|
||||
.replace("é", "e")
|
||||
.replace("ú", "u")
|
||||
.replace("†", "+")
|
||||
.replace("★", "*")
|
||||
.replace("ó", "o")
|
||||
.replace("ä", "a")
|
||||
.replace("ü", "u")
|
||||
.replace("É", "E")
|
||||
.replace("ñ", "n")
|
||||
.replace("®", "");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue