Fixed mtgjson data;

This commit is contained in:
Oleg Agafonov 2018-12-07 07:34:38 +04:00
parent 1986b01bf6
commit a4d797e473
3 changed files with 43 additions and 21 deletions

View file

@ -34,6 +34,8 @@ class JsonCard {
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;
@ -44,8 +46,4 @@ class JsonCard {
public String uuid;
public List<String> variations;
public String watermark;
// unknown
public boolean starter;
public String side;
}

View file

@ -12,7 +12,10 @@ import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.Normalizer;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipInputStream;
public final class MtgJson {
@ -60,16 +63,29 @@ public final class MtgJson {
static {
try {
cards = loadAllCards();
List<String> oldKeys = new ArrayList<>();
List<String> keysToDelete = new ArrayList<>();
// fix names
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);
keysToDelete.add(key);
}
}
cards.putAll(newKeys);
cards.keySet().removeAll(oldKeys);
cards.keySet().removeAll(keysToDelete);
// remove wrong data (tokens)
keysToDelete.clear();
for (Map.Entry<String, JsonCard> record : cards.entrySet()) {
if (record.getValue().layout.equals("token") || record.getValue().layout.equals("double_faced_token")) {
keysToDelete.add(record.getKey());
}
}
cards.keySet().removeAll(keysToDelete);
addAliases(cards);
} catch (IOException e) {
throw new RuntimeException(e);