mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
Tests: simplify mtgjson code in verify test;
This commit is contained in:
parent
bdac0b3d72
commit
e1806f808c
11 changed files with 74 additions and 209 deletions
|
|
@ -1,58 +0,0 @@
|
|||
package mage.verify;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
|
||||
class JsonCard {
|
||||
// docs: https://mtgjson.com/v4/docs.html
|
||||
|
||||
public String artist;
|
||||
public String borderColor;
|
||||
public List<String> colorIdentity;
|
||||
public List<String> colorIndicator;
|
||||
public List<String> colors;
|
||||
public float convertedManaCost;
|
||||
public float faceConvertedManaCost;
|
||||
public String flavorText;
|
||||
public List<JsonForeignData> foreignData;
|
||||
public String frameVersion;
|
||||
public boolean hasFoil;
|
||||
public boolean hasNonFoil;
|
||||
public boolean isOnlineOnly;
|
||||
public boolean isOversized;
|
||||
public boolean isReserved;
|
||||
public boolean isTimeshifted;
|
||||
public String layout;
|
||||
public JsonLegalities legalities;
|
||||
public String loyalty;
|
||||
public String manaCost;
|
||||
public int multiverseId;
|
||||
public String name;
|
||||
public List<String> names;
|
||||
public String number;
|
||||
public String originalText;
|
||||
public String originalType;
|
||||
public List<String> printings;
|
||||
public String power;
|
||||
public String rarity;
|
||||
public boolean starter;
|
||||
public String side;
|
||||
public List<JsonRuling> rulings;
|
||||
public List<String> subtypes;
|
||||
public List<String> supertypes;
|
||||
public String text;
|
||||
public String toughness;
|
||||
public String type;
|
||||
public List<String> types;
|
||||
public String uuid;
|
||||
public List<String> variations;
|
||||
public String watermark;
|
||||
public String tcgplayerProductId;
|
||||
public String scryfallId;
|
||||
public boolean isAlternative;
|
||||
public String frameEffect;
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package mage.verify;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
|
||||
public class JsonForeignData {
|
||||
public String flavorText;
|
||||
public String language;
|
||||
public int multiverseId;
|
||||
public String name;
|
||||
public String text;
|
||||
public String type;
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package mage.verify;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
|
||||
public class JsonLegalities {
|
||||
@JsonProperty("1v1")
|
||||
public String oneVersusOne;
|
||||
public String brawl;
|
||||
public String commander;
|
||||
public String duel;
|
||||
public String frontier;
|
||||
public String future;
|
||||
public String legacy;
|
||||
public String modern;
|
||||
public String penny;
|
||||
public String pauper;
|
||||
public String standard;
|
||||
public String vintage;
|
||||
public String oldschool;
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package mage.verify;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
|
||||
public class JsonMeta {
|
||||
public String date;
|
||||
public String version;
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package mage.verify;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
|
||||
public class JsonRuling {
|
||||
public String date;
|
||||
public String text;
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package mage.verify;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
|
||||
class JsonSet {
|
||||
public int baseSetSize;
|
||||
public String block;
|
||||
public List<Object> boosterV3; // [["rare", "mythic rare"], "uncommon", "uncommon", "uncommon", "common"]
|
||||
public List<JsonCard> cards;
|
||||
public String code;
|
||||
public boolean isFoilOnly;
|
||||
public boolean isOnlineOnly;
|
||||
public JsonMeta meta;
|
||||
public String mtgoCode;
|
||||
public String name;
|
||||
public String releaseDate;
|
||||
public List<JsonToken> tokens;
|
||||
public int totalSetSize;
|
||||
public String type;
|
||||
public String tcgplayerGroupId;
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
package mage.verify;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
|
||||
public class JsonToken {
|
||||
public String artist;
|
||||
public String borderColor;
|
||||
public List<String> colorIdentity;
|
||||
public List<String> colorIndicator;
|
||||
public List<String> colors;
|
||||
public String loyalty;
|
||||
public String name;
|
||||
public String number;
|
||||
public String power;
|
||||
public List<String> reverseRelated;
|
||||
public String side;
|
||||
public String text;
|
||||
public String toughness;
|
||||
public String type;
|
||||
public String uuid;
|
||||
public String watermark;
|
||||
public boolean isOnlineOnly;
|
||||
public String scryfallId;
|
||||
}
|
||||
23
Mage.Verify/src/main/java/mage/verify/MtgJsonCard.java
Normal file
23
Mage.Verify/src/main/java/mage/verify/MtgJsonCard.java
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package mage.verify;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static mage.verify.MtgJsonService.MTGJSON_IGNORE_NEW_PROPERTIES;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
|
||||
class MtgJsonCard {
|
||||
// docs: https://mtgjson.com/v4/docs.html
|
||||
public List<String> colorIdentity;
|
||||
public List<String> colors;
|
||||
public String layout;
|
||||
public String manaCost;
|
||||
public String number;
|
||||
public String power;
|
||||
public List<String> subtypes;
|
||||
public List<String> supertypes;
|
||||
public String text;
|
||||
public String toughness;
|
||||
public List<String> types;
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
public final class MtgJson {
|
||||
public final class MtgJsonService {
|
||||
|
||||
public static Map<String, String> mtgJsonToXMageCodes = new HashMap<>();
|
||||
public static Map<String, String> xMageToMtgJsonCodes = new HashMap<>();
|
||||
|
|
@ -49,11 +49,11 @@ public final class MtgJson {
|
|||
}
|
||||
}
|
||||
|
||||
private MtgJson() {
|
||||
private MtgJsonService() {
|
||||
}
|
||||
|
||||
private static final class CardHolder {
|
||||
private static final Map<String, JsonCard> cards;
|
||||
private static final Map<String, MtgJsonCard> cards;
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -62,7 +62,7 @@ public final class MtgJson {
|
|||
List<String> keysToDelete = new ArrayList<>();
|
||||
|
||||
// fix names
|
||||
Map<String, JsonCard> newKeys = new HashMap<>();
|
||||
Map<String, MtgJsonCard> newKeys = new HashMap<>();
|
||||
for (String key : cards.keySet()) {
|
||||
if (key.contains("(")) {
|
||||
newKeys.put(key.replaceAll("\\(.*\\)", "").trim(), cards.get(key));
|
||||
|
|
@ -74,7 +74,7 @@ public final class MtgJson {
|
|||
|
||||
// remove wrong data (tokens)
|
||||
keysToDelete.clear();
|
||||
for (Map.Entry<String, JsonCard> record : cards.entrySet()) {
|
||||
for (Map.Entry<String, MtgJsonCard> record : cards.entrySet()) {
|
||||
if (record.getValue().layout.equals("token") || record.getValue().layout.equals("double_faced_token")) {
|
||||
keysToDelete.add(record.getKey());
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ public final class MtgJson {
|
|||
}
|
||||
|
||||
private static final class SetHolder {
|
||||
private static final Map<String, JsonSet> sets;
|
||||
private static final Map<String, MtgJsonSet> sets;
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -100,18 +100,18 @@ public final class MtgJson {
|
|||
}
|
||||
}
|
||||
|
||||
private static Map<String, JsonCard> loadAllCards() throws IOException {
|
||||
return readFromZip("AllCards.json.zip", new TypeReference<Map<String, JsonCard>>() {
|
||||
private static Map<String, MtgJsonCard> loadAllCards() throws IOException {
|
||||
return readFromZip("AllCards.json.zip", new TypeReference<Map<String, MtgJsonCard>>() {
|
||||
});
|
||||
}
|
||||
|
||||
private static Map<String, JsonSet> loadAllSets() throws IOException {
|
||||
return readFromZip("AllPrintings.json.zip", new TypeReference<Map<String, JsonSet>>() {
|
||||
private static Map<String, MtgJsonSet> loadAllSets() throws IOException {
|
||||
return readFromZip("AllPrintings.json.zip", new TypeReference<Map<String, MtgJsonSet>>() {
|
||||
});
|
||||
}
|
||||
|
||||
private static <T> T readFromZip(String filename, TypeReference<T> ref) throws IOException {
|
||||
InputStream stream = MtgJson.class.getResourceAsStream(filename);
|
||||
InputStream stream = MtgJsonService.class.getResourceAsStream(filename);
|
||||
if (stream == null) {
|
||||
File file = new File(filename);
|
||||
if (!file.exists()) {
|
||||
|
|
@ -133,11 +133,11 @@ public final class MtgJson {
|
|||
|
||||
}
|
||||
|
||||
public static Map<String, JsonSet> sets() {
|
||||
public static Map<String, MtgJsonSet> sets() {
|
||||
return SetHolder.sets;
|
||||
}
|
||||
|
||||
public static JsonCard card(String name) {
|
||||
public static MtgJsonCard card(String name) {
|
||||
return findReference(CardHolder.cards, name);
|
||||
}
|
||||
|
||||
16
Mage.Verify/src/main/java/mage/verify/MtgJsonSet.java
Normal file
16
Mage.Verify/src/main/java/mage/verify/MtgJsonSet.java
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package mage.verify;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static mage.verify.MtgJsonService.MTGJSON_IGNORE_NEW_PROPERTIES;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
|
||||
class MtgJsonSet {
|
||||
public List<MtgJsonCard> cards;
|
||||
public String code;
|
||||
public String name;
|
||||
public String releaseDate;
|
||||
public int totalSetSize;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue