suppert mtgjson v4

This commit is contained in:
Ingmar Goudt 2018-11-23 19:21:03 +01:00
parent 2e17cb334e
commit d9b25cbac1
10 changed files with 136 additions and 21 deletions

View file

@ -0,0 +1,8 @@
package mage.verify;
public class Booster {
public Booster(String mythic){
}
}

View file

@ -0,0 +1,12 @@
package mage.verify;
public class ForeignData {
public String language;
public String name;
public String type;
public String text;
public String flavorText;
public String multiverseId;
}

View file

@ -3,10 +3,23 @@ package mage.verify;
import java.util.List;
class JsonCard {
public String uuid;
public String convertedManaCost;
public List<ForeignData> foreignData;
public boolean isReserved;
public String side;
public Legality legalities;
public List<String> printings;
public List<Ruling> rulings;
public List<String> colorIndicator;
public String layout;
public String name;
public List<String> names; // flip cards
public String manaCost;
public boolean hasFoil;
public boolean hasNonFoil;
public String multiverseId;
public String frameVersion;
public int cmc;
public List<String> colors;
public List<String> colorIdentity;
@ -22,6 +35,10 @@ class JsonCard {
public boolean starter; // only available in boxed sets and not in boosters
public int hand; // vanguard
public int life; // vanguard
public String originalText;
public String originalType;
public String flavorText;
public boolean isOnlineOnly;
// only available in AllSets.json
public String artist;
@ -37,4 +54,6 @@ class JsonCard {
public String border;
public String watermark;
public boolean timeshifted;
public String borderColor;
public boolean isOversized;
}

View file

@ -1,5 +1,7 @@
package mage.verify;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.List;
import java.util.Map;
@ -21,4 +23,14 @@ class JsonSet {
public String mkm_id;
public String mkm_name;
public Map<String, String> translations;
public int baseSetSize;
@JsonIgnore
public List<Booster> boosterV3;
public String borderColor;
public Meta meta;
public String mtgoCode;
public List<Token> tokens;
public int totalSetSize;
public boolean isOnlineOnly;
public boolean isFoilOnly;
}

View file

@ -0,0 +1,19 @@
package mage.verify;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Legality {
@JsonProperty("1v1")
public String oneVersusOne;
public String commander;
public String duel;
public String legacy;
public String penny;
public String vintage;
public String frontier;
public String modern;
public String pauper;
public String brawl;
public String future;
public String standard;
}

View file

@ -0,0 +1,6 @@
package mage.verify;
public class Meta {
public String date;
public String version;
}

View file

@ -12,8 +12,7 @@ import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.Normalizer;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.zip.ZipInputStream;
public final class MtgJson {
@ -61,6 +60,16 @@ public final class MtgJson {
static {
try {
cards = loadAllCards();
List<String> oldKeys = new ArrayList<>();
Map<String, JsonCard> newKeys = new HashMap<>();
for (String key : cards.keySet()) {
if (key.contains("(")) {
newKeys.put(key.replaceAll("\\(.*\\)", "").trim(), cards.get(key));
oldKeys.add(key);
}
}
cards.putAll(newKeys);
cards.keySet().removeAll(oldKeys);
addAliases(cards);
} catch (IOException e) {
throw new RuntimeException(e);
@ -95,7 +104,7 @@ public final class MtgJson {
if (stream == null) {
File file = new File(filename);
if (!file.exists()) {
InputStream download = new URL("http://mtgjson.com/json/" + filename).openStream();
InputStream download = new URL("http://mtgjson.com/v4/json/" + filename).openStream();
Files.copy(download, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
System.out.println("Downloaded " + filename + " to " + file.getAbsolutePath());
} else {
@ -133,6 +142,7 @@ public final class MtgJson {
name = name.replace("'", "\""); // for Kongming, "Sleeping Dragon" & Pang Tong, "Young Phoenix"
ref = reference.get(name);
}
return ref;
}

View file

@ -0,0 +1,6 @@
package mage.verify;
public class Ruling {
public String text;
public String date;
}

View file

@ -0,0 +1,19 @@
package mage.verify;
import java.util.List;
public class Token {
public String artist;
public String borderColor;
public List<String> colorIdentity;
public List<String> colors;
public String name;
public String number;
public String power;
public String toughness;
public List<String> reverseRelated;
public String text;
public String type;
public String uuid;
public String watermark;
}

View file

@ -1,14 +1,13 @@
package mage.verify;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.keyword.DevoidAbility;
import mage.abilities.keyword.MultikickerAbility;
import mage.cards.*;
import mage.cards.basiclands.BasicLand;
import mage.cards.repository.CardRepository;
import mage.cards.repository.CardScanner;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.game.permanent.token.Token;
import mage.game.permanent.token.TokenImpl;
@ -232,7 +231,7 @@ public class VerifyCardDataTest {
// replace codes for aliases
String searchSet = MtgJson.mtgJsonToXMageCodes.getOrDefault(refSet.code, refSet.code);
ExpansionSet mageSet = Sets.findSet(searchSet);
ExpansionSet mageSet = Sets.findSet(searchSet.toUpperCase());
if (mageSet == null) {
totalMissingSets = totalMissingSets + 1;
totalMissingCards = totalMissingCards + refSet.cards.size();
@ -383,7 +382,7 @@ public class VerifyCardDataTest {
// check
for (ExpansionSet.SetCardInfo card : set.getSetCardInfo()) {
boolean cardHaveDoubleName = (doubleNames.getOrDefault(card.getName(), 0) > 1);
boolean cardHaveVariousSetting = card.getGraphicInfo() == null ? false : card.getGraphicInfo().getUsesVariousArt();
boolean cardHaveVariousSetting = card.getGraphicInfo() != null && card.getGraphicInfo().getUsesVariousArt();
if (cardHaveDoubleName && !cardHaveVariousSetting) {
errorsList.add("error, founded double card names, but UsesVariousArt is not true: " + set.getCode() + " - " + set.getName() + " - " + card.getName() + " - " + card.getCardNumber());
@ -569,17 +568,22 @@ public class VerifyCardDataTest {
return;
}
Collection<String> expected = ref.colors;
ObjectColor color = card.getColor(null);
if (expected == null) {
expected = Collections.emptyList();
Set<String> expected = new HashSet<>();
if (ref.colors != null) {
expected.addAll(ref.colors);
}
if(card.isFlipCard()){
expected.addAll(ref.colorIdentity);
}
ObjectColor color = card.getColor(null);
if (expected.size() != color.getColorCount()
|| (color.isBlack() && !expected.contains("Black"))
|| (color.isBlue() && !expected.contains("Blue"))
|| (color.isGreen() && !expected.contains("Green"))
|| (color.isRed() && !expected.contains("Red"))
|| (color.isWhite() && !expected.contains("White"))) {
|| (color.isBlack() && !expected.contains("B"))
|| (color.isBlue() && !expected.contains("U"))
|| (color.isGreen() && !expected.contains("G"))
|| (color.isRed() && !expected.contains("R"))
|| (color.isWhite() && !expected.contains("W"))) {
fail(card, "colors", color + " != " + expected);
}
}
@ -601,7 +605,7 @@ public class VerifyCardDataTest {
}
}
if (!eqSet(card.getSubtype(null).stream().map(p -> p.toString()).collect(Collectors.toSet()), expected)) {
if (!eqSet(card.getSubtype(null).stream().map(SubType::toString).collect(Collectors.toSet()), expected)) {
fail(card, "subtypes", card.getSubtype(null) + " != " + expected);
}
}
@ -628,11 +632,11 @@ public class VerifyCardDataTest {
}
// special check: kicker ability must be in rules
if (card.getAbilities().containsClass(MultikickerAbility.class) && !card.getRules().stream().anyMatch(rule -> rule.contains("Multikicker"))) {
if (card.getAbilities().containsClass(MultikickerAbility.class) && card.getRules().stream().noneMatch(rule -> rule.contains("Multikicker"))) {
fail(card, "abilities", "card have Multikicker ability, but missing it in rules text");
}
// spells have only 1 abilities
// spells have only 1 ability
if (card.isSorcery() || card.isInstant()) {
return;
}
@ -697,7 +701,7 @@ public class VerifyCardDataTest {
String expected = ref.manaCost;
String cost = join(card.getManaCost().getSymbols());
if (cost != null && cost.isEmpty()) {
if (cost.isEmpty()) {
cost = null;
}
if (cost != null) {