Search in sources :

Example 1 with TokenImpl

use of mage.game.permanent.token.TokenImpl in project mage by magefree.

the class VerifyCardDataTest method test_checkMissingTokenData.

@Test
// TODO: enable test after massive token fixes
@Ignore
public void test_checkMissingTokenData() {
    Collection<String> errorsList = new ArrayList<>();
    Collection<String> warningsList = new ArrayList<>();
    // all tokens must be stores in card-pictures-tok.txt (if not then viewer and image downloader are missing token images)
    // https://github.com/ronmamo/reflections
    Reflections reflections = new Reflections("mage.");
    Set<Class<? extends TokenImpl>> tokenClassesList = reflections.getSubTypesOf(TokenImpl.class);
    // xmage tokens
    Set<Class<? extends TokenImpl>> privateTokens = new HashSet<>();
    Set<Class<? extends TokenImpl>> publicTokens = new HashSet<>();
    for (Class<? extends TokenImpl> tokenClass : tokenClassesList) {
        if (Modifier.isPublic(tokenClass.getModifiers())) {
            publicTokens.add(tokenClass);
        } else {
            privateTokens.add(tokenClass);
        }
    }
    // tok file's data
    List<CardDownloadData> tokFileTokens = DownloadPicturesService.getTokenCardUrls();
    LinkedHashMap<String, String> tokDataClassesIndex = new LinkedHashMap<>();
    LinkedHashMap<String, String> tokDataNamesIndex = new LinkedHashMap<>();
    for (CardDownloadData tokData : tokFileTokens) {
        String searchName;
        String setsList;
        // by class
        searchName = tokData.getTokenClassName();
        setsList = tokDataClassesIndex.getOrDefault(searchName, "");
        if (!setsList.isEmpty()) {
            setsList += ",";
        }
        setsList += tokData.getSet();
        tokDataClassesIndex.put(searchName, setsList);
        // by name
        searchName = tokData.getName();
        setsList = tokDataNamesIndex.getOrDefault(searchName, "");
        if (!setsList.isEmpty()) {
            setsList += ",";
        }
        setsList += tokData.getSet();
        tokDataNamesIndex.put(searchName, setsList);
    }
    // 1. check token name convention
    for (Class<? extends TokenImpl> tokenClass : tokenClassesList) {
        if (!tokenClass.getName().endsWith("Token")) {
            String className = extractShortClass(tokenClass);
            warningsList.add("warning, token class must ends with Token: " + className + " from " + tokenClass.getName());
        }
    }
    // 2. check store file for public
    for (Class<? extends TokenImpl> tokenClass : publicTokens) {
        String fullClass = tokenClass.getName();
        if (!fullClass.startsWith("mage.game.permanent.token.")) {
            String className = extractShortClass(tokenClass);
            errorsList.add("Error: public token must stores in mage.game.permanent.token package: " + className + " from " + tokenClass.getName());
        }
    }
    // 3. check private tokens (they aren't need at all)
    for (Class<? extends TokenImpl> tokenClass : privateTokens) {
        String className = extractShortClass(tokenClass);
        errorsList.add("Error: no needs in private tokens, replace it with CreatureToken: " + className + " from " + tokenClass.getName());
    }
    // 4. all public tokens must have tok-data (private tokens uses for innner abilities -- no need images for it)
    for (Class<? extends TokenImpl> tokenClass : publicTokens) {
        String className = extractShortClass(tokenClass);
        Token token = (Token) createNewObject(tokenClass);
        if (token == null) {
            errorsList.add("Error: token must have default constructor with zero params: " + tokenClass.getName());
        } else if (tokDataNamesIndex.getOrDefault(token.getName(), "").isEmpty()) {
            errorsList.add("Error: can't find data in card-pictures-tok.txt for token: " + tokenClass.getName() + " -> " + token.getName());
        }
    }
    // TODO: all sets must have full tokens data in tok file (token in every set)
    // 1. Download scryfall tokens list: https://api.scryfall.com/cards/search?q=t:token
    // 2. Proccess each token with all prints: read "prints_search_uri" field from token data and go to link like
    // https://api.scryfall.com/cards/search?order=set&q=%21%E2%80%9CAngel%E2%80%9D&unique=prints
    // 3. Collect all strings in "set@name"
    // 4. Proccess tokens data and find missing strings from "set@name" list
    printMessages(warningsList);
    printMessages(errorsList);
    if (errorsList.size() > 0) {
        Assert.fail("Found token errors: " + errorsList.size());
    }
// TODO: all token must have correct availableImageSetCodes (all sets with that token)
// Some sets have original card, but don't have token card at all. So you must use scryfall tokens list above to find
// all token's sets and compare with xmage
}
Also used : CardDownloadData(org.mage.plugins.card.images.CardDownloadData) TokenImpl(mage.game.permanent.token.TokenImpl) Token(mage.game.permanent.token.Token) Reflections(org.reflections.Reflections) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Token (mage.game.permanent.token.Token)1 TokenImpl (mage.game.permanent.token.TokenImpl)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 CardDownloadData (org.mage.plugins.card.images.CardDownloadData)1 Reflections (org.reflections.Reflections)1