Search in sources :

Example 1 with MtgJsonCard

use of mage.verify.mtgjson.MtgJsonCard in project mage by magefree.

the class VerifyCardDataTest method checkSubtypes.

private void checkSubtypes(Card card, MtgJsonCard ref) {
    if (skipListHaveName(SKIP_LIST_SUBTYPE, card.getExpansionSetCode(), card.getName())) {
        return;
    }
    Collection<String> expected = ref.subtypes;
    // fix names (e.g. Urza’s to Urza's)
    if (expected != null && expected.contains("Urza’s")) {
        expected = new ArrayList<>(expected);
        for (ListIterator<String> it = ((List<String>) expected).listIterator(); it.hasNext(); ) {
            if (it.next().equals("Urza’s")) {
                it.set("Urza's");
            }
        }
    }
    // Remove subtypes that need to be ignored
    Collection<String> actual = card.getSubtype().stream().map(SubType::toString).collect(Collectors.toSet());
    actual.removeIf(subtypesToIgnore::contains);
    if (expected != null) {
        expected.removeIf(subtypesToIgnore::contains);
    }
    for (SubType subType : card.getSubtype()) {
        if (!subType.isCustomSet() && !subType.canGain(card)) {
            String cardTypeString = card.getCardType().stream().map(CardType::toString).reduce((a, b) -> a + " " + b).orElse("");
            fail(card, "subtypes", "card has subtype " + subType.getDescription() + " (" + subType.getSubTypeSet() + ')' + " that doesn't match its card type(s) (" + cardTypeString + ')');
        }
    }
    if (!eqSet(actual, expected)) {
        fail(card, "subtypes", actual + " != " + expected);
    }
}
Also used : SagaAbility(mage.abilities.common.SagaAbility) WerewolfBackTriggeredAbility(mage.abilities.common.WerewolfBackTriggeredAbility) CardScanner(mage.cards.repository.CardScanner) Reflections(org.reflections.Reflections) ScryEffect(mage.abilities.effects.keyword.ScryEffect) java.nio.file(java.nio.file) RateCard(mage.game.draft.RateCard) Logger(org.apache.log4j.Logger) DraftCube(mage.game.draft.DraftCube) TransformAbility(mage.abilities.keyword.TransformAbility) CardType(mage.constants.CardType) ObjectColor(mage.ObjectColor) Method(java.lang.reflect.Method) mage.cards(mage.cards) FightTargetsEffect(mage.abilities.effects.common.FightTargetsEffect) DeckImporter(mage.cards.decks.importer.DeckImporter) Plane(mage.game.command.Plane) CardUtil(mage.util.CardUtil) CardRepository(mage.cards.repository.CardRepository) Collectors(java.util.stream.Collectors) InvocationTargetException(java.lang.reflect.InvocationTargetException) TherosBeyondDeath(mage.sets.TherosBeyondDeath) Dungeon(mage.game.command.Dungeon) Watcher(mage.watchers.Watcher) Token(mage.game.permanent.token.Token) Effect(mage.abilities.effects.Effect) Modifier(java.lang.reflect.Modifier) MultikickerAbility(mage.abilities.keyword.MultikickerAbility) Rarity(mage.constants.Rarity) java.util(java.util) TokenImpl(mage.game.permanent.token.TokenImpl) SubType(mage.constants.SubType) Constructor(java.lang.reflect.Constructor) Mode(mage.abilities.Mode) EnchantAbility(mage.abilities.keyword.EnchantAbility) DownloadPicturesService(org.mage.plugins.card.images.DownloadPicturesService) MenaceAbility(mage.abilities.keyword.MenaceAbility) DeckCardLists(mage.cards.decks.DeckCardLists) ScryfallImageSupportCards(org.mage.plugins.card.dl.sources.ScryfallImageSupportCards) CharMatcher(com.google.common.base.CharMatcher) Test(org.junit.Test) CardDownloadData(org.mage.plugins.card.images.CardDownloadData) IOException(java.io.IOException) MtgJsonCard(mage.verify.mtgjson.MtgJsonCard) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) MtgJsonSet(mage.verify.mtgjson.MtgJsonSet) MtgJsonService(mage.verify.mtgjson.MtgJsonService) WerewolfFrontTriggeredAbility(mage.abilities.common.WerewolfFrontTriggeredAbility) Ignore(org.junit.Ignore) CardInfo(mage.cards.repository.CardInfo) Assert(org.junit.Assert) SuperType(mage.constants.SuperType) Ability(mage.abilities.Ability) SubType(mage.constants.SubType) CardType(mage.constants.CardType)

Example 2 with MtgJsonCard

use of mage.verify.mtgjson.MtgJsonCard in project mage by magefree.

the class VerifyCardDataTest method test_checkWrongCardsDataInSets.

@Test
// TODO: enable after all missing cards and settings fixes
@Ignore
public void test_checkWrongCardsDataInSets() {
    Collection<String> errorsList = new ArrayList<>();
    Collection<String> warningsList = new ArrayList<>();
    Collection<ExpansionSet> xmageSets = Sets.getInstance().values();
    Set<String> foundedJsonCards = new HashSet<>();
    // CHECK: wrong card numbers
    for (ExpansionSet set : xmageSets) {
        if (skipListHaveName(SKIP_LIST_WRONG_CARD_NUMBERS, set.getCode())) {
            continue;
        }
        for (ExpansionSet.SetCardInfo card : set.getSetCardInfo()) {
            MtgJsonCard jsonCard = MtgJsonService.cardFromSet(set.getCode(), card.getName(), card.getCardNumber());
            if (jsonCard == null) {
                // see convertMtgJsonToXmageCardNumber for card number convert notation
                errorsList.add("Error: unknown card number or set, use standard number notations: " + set.getCode() + " - " + set.getName() + " - " + card.getName() + " - " + card.getCardNumber());
                continue;
            }
            // index for missing cards
            String code = MtgJsonService.xMageToMtgJsonCodes.getOrDefault(set.getCode(), set.getCode()) + " - " + jsonCard.getRealCardName() + " - " + jsonCard.number;
            foundedJsonCards.add(code);
            // CHECK: only lands can use full art in current version;
            // Another cards must be in text render mode as normal, example: https://scryfall.com/card/sld/76/athreos-god-of-passage
            boolean isLand = card.getRarity().equals(Rarity.LAND);
            if (card.isFullArt() && !isLand) {
                errorsList.add("Error: only lands can use full art setting: " + set.getCode() + " - " + set.getName() + " - " + card.getName() + " - " + card.getCardNumber());
            }
            // CHECK: must use full art setting
            if (jsonCard.isFullArt && isLand && !card.isFullArt()) {
                errorsList.add("Error: card must use full art setting: " + set.getCode() + " - " + set.getName() + " - " + card.getName() + " - " + card.getCardNumber());
            }
            // CHECK: must not use full art setting
            if (!jsonCard.isFullArt && card.isFullArt()) {
                errorsList.add("Error: card must NOT use full art setting: " + set.getCode() + " - " + set.getName() + " - " + card.getName() + " - " + card.getCardNumber());
            }
        }
    }
    // CHECK: missing cards from set
    for (MtgJsonSet jsonSet : MtgJsonService.sets().values()) {
        if (skipListHaveName(SKIP_LIST_UNSUPPORTED_SETS, jsonSet.code) || skipListHaveName(SKIP_LIST_WRONG_CARD_NUMBERS, jsonSet.code)) {
            continue;
        }
        ExpansionSet xmageSet = Sets.findSet(jsonSet.code);
        if (xmageSet == null) {
            warningsList.add("Warning: found un-implemented set from mtgjson database: " + jsonSet.code + " - " + jsonSet.name + " - " + jsonSet.releaseDate);
            continue;
        }
        for (MtgJsonCard jsonCard : jsonSet.cards) {
            String code = jsonSet.code + " - " + jsonCard.getRealCardName() + " - " + jsonCard.number;
            if (!foundedJsonCards.contains(code)) {
                if (CardRepository.instance.findCard(jsonCard.getRealCardName()) == null) {
                    // ignore non-implemented cards
                    continue;
                }
                errorsList.add("Error: missing card from xmage's set: " + jsonSet.code + " - " + jsonCard.getRealCardName() + " - " + jsonCard.number);
            }
        }
    }
    printMessages(warningsList);
    printMessages(errorsList);
    if (errorsList.size() > 0) {
        Assert.fail("Found wrong cards data in sets, errors: " + errorsList.size());
    }
}
Also used : MtgJsonSet(mage.verify.mtgjson.MtgJsonSet) MtgJsonCard(mage.verify.mtgjson.MtgJsonCard) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with MtgJsonCard

use of mage.verify.mtgjson.MtgJsonCard in project mage by magefree.

the class VerifyCardDataTest method test_checkMissingScryfallSettingsAndCardNumbers.

@Test
// TODO: enable after all missing cards and settings fixes
@Ignore
public void test_checkMissingScryfallSettingsAndCardNumbers() {
    Collection<String> errorsList = new ArrayList<>();
    Collection<ExpansionSet> xmageSets = Sets.getInstance().values();
    Set<String> scryfallSets = ScryfallImageSupportCards.getSupportedSets();
    // CHECK: missing sets in supported list
    for (ExpansionSet set : xmageSets) {
        if (skipListHaveName(SKIP_LIST_SCRYFALL_DOWNLOAD_SETS, set.getCode())) {
            continue;
        }
        if (!scryfallSets.contains(set.getCode())) {
            errorsList.add("Error: scryfall download missing setting: " + set.getCode() + " - " + set.getName());
        }
    }
    // CHECK: unknown sets in supported list
    for (String scryfallCode : scryfallSets) {
        if (xmageSets.stream().noneMatch(e -> e.getCode().equals(scryfallCode))) {
            errorsList.add("Error: scryfall download unknown setting: " + scryfallCode);
        }
    }
    // card numbers
    // all cards with non-ascii numbers must be downloaded by direct links (api)
    Set<String> foundedDirectDownloadKeys = new HashSet<>();
    for (ExpansionSet set : xmageSets) {
        if (skipListHaveName(SKIP_LIST_SCRYFALL_DOWNLOAD_SETS, set.getCode()) || skipListHaveName(SKIP_LIST_WRONG_CARD_NUMBERS, set.getCode())) {
            continue;
        }
        for (ExpansionSet.SetCardInfo card : set.getSetCardInfo()) {
            if (skipListHaveName(SKIP_LIST_WRONG_CARD_NUMBERS, set.getCode(), card.getName())) {
                continue;
            }
            MtgJsonCard jsonCard = MtgJsonService.cardFromSet(set.getCode(), card.getName(), card.getCardNumber());
            if (jsonCard == null) {
                // see convertMtgJsonToXmageCardNumber for card number convert notation
                if (!skipListHaveName(SKIP_LIST_WRONG_CARD_NUMBERS, set.getCode(), card.getName())) {
                    errorsList.add("Error: scryfall download can't find card from mtgjson " + set.getCode() + " - " + set.getName() + " - " + card.getName() + " - " + card.getCardNumber());
                }
                continue;
            }
            // CHECK: non-ascii numbers and direct download list
            if (!CharMatcher.ascii().matchesAllOf(jsonCard.number)) {
                // non-ascii numbers
                // xmage card numbers can't have non-ascii numbers (it checked by test_checkMissingCardData)
                String key = ScryfallImageSupportCards.findDirectDownloadKey(set.getCode(), card.getName(), card.getCardNumber());
                if (key != null) {
                    foundedDirectDownloadKeys.add(key);
                } else {
                    errorsList.add("Error: scryfall download can't find non-ascii card link in direct download list " + set.getCode() + " - " + set.getName() + " - " + card.getName() + " - " + jsonCard.number);
                }
            }
            // CHECK: reversible_card must be in direct download list (xmage must have 2 cards with diff image face)
            if (jsonCard.layout.equals("reversible_card")) {
                String key = ScryfallImageSupportCards.findDirectDownloadKey(set.getCode(), card.getName(), card.getCardNumber());
                if (key != null) {
                    foundedDirectDownloadKeys.add(key);
                } else {
                    errorsList.add("Error: scryfall download can't find face image of reversible_card in direct download list " + set.getCode() + " - " + set.getName() + " - " + card.getName() + " - " + jsonCard.number);
                }
            }
        }
    }
    // CHECK: unknown direct download links
    for (Map.Entry<String, String> direct : ScryfallImageSupportCards.getDirectDownloadLinks().entrySet()) {
        // skip custom sets
        String setCode = ScryfallImageSupportCards.extractSetCodeFromDirectKey(direct.getKey());
        String cardName = ScryfallImageSupportCards.extractCardNameFromDirectKey(direct.getKey());
        if (skipListHaveName(SKIP_LIST_SCRYFALL_DOWNLOAD_SETS, setCode) || skipListHaveName(SKIP_LIST_WRONG_CARD_NUMBERS, setCode)) {
            continue;
        }
        // skip non-implemented cards list
        if (CardRepository.instance.findCard(cardName) == null) {
            continue;
        }
        if (!foundedDirectDownloadKeys.contains(direct.getKey())) {
            errorsList.add("Error: scryfall download found unknown direct download link " + direct.getKey() + " - " + direct.getValue());
        }
    }
    printMessages(errorsList);
    if (errorsList.size() > 0) {
        Assert.fail("Found scryfall download errors: " + errorsList.size());
    }
}
Also used : MtgJsonCard(mage.verify.mtgjson.MtgJsonCard) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

MtgJsonCard (mage.verify.mtgjson.MtgJsonCard)3 Ignore (org.junit.Ignore)3 Test (org.junit.Test)3 MtgJsonSet (mage.verify.mtgjson.MtgJsonSet)2 CharMatcher (com.google.common.base.CharMatcher)1 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 java.nio.file (java.nio.file)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 ObjectColor (mage.ObjectColor)1 Ability (mage.abilities.Ability)1 Mode (mage.abilities.Mode)1 SagaAbility (mage.abilities.common.SagaAbility)1 WerewolfBackTriggeredAbility (mage.abilities.common.WerewolfBackTriggeredAbility)1 WerewolfFrontTriggeredAbility (mage.abilities.common.WerewolfFrontTriggeredAbility)1