mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
tests: improved test_showCardInfo, now it can show mtgjson ref data without set usage (VSC script support)
This commit is contained in:
parent
fda9d8fc1d
commit
0cf0af3cbb
2 changed files with 18 additions and 1 deletions
|
|
@ -75,6 +75,11 @@ public final class MtgJsonService {
|
|||
return findReference(CardHolder.cards, name);
|
||||
}
|
||||
|
||||
public static MtgJsonCard cardByClassName(String classFullName) {
|
||||
String shortName = classFullName.replaceAll(".*\\.", "").toLowerCase(Locale.ENGLISH);
|
||||
return findReference(CardHolder.cardsByClasses, shortName);
|
||||
}
|
||||
|
||||
public static List<MtgJsonCard> cardsFromSet(String setCode, String name) {
|
||||
MtgJsonSet set = findReference(SetHolder.sets, setCode);
|
||||
if (set == null) {
|
||||
|
|
@ -179,7 +184,8 @@ public final class MtgJsonService {
|
|||
}
|
||||
|
||||
private static final class CardHolder {
|
||||
private static final Map<String, MtgJsonCard> cards;
|
||||
private static final Map<String, MtgJsonCard> cards; // key: card name like Grizzly Bears
|
||||
private static final Map<String, MtgJsonCard> cardsByClasses; // key: short class name in lower case like grizzlybears
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -208,6 +214,14 @@ public final class MtgJsonService {
|
|||
cards.keySet().removeAll(keysToDelete);
|
||||
|
||||
addAliases(cards);
|
||||
|
||||
// create index for class names searching
|
||||
// lower case with ascii symbols without space
|
||||
cardsByClasses = new HashMap<>(cards.size());
|
||||
cards.forEach((name, card) -> {
|
||||
String className = name.replaceAll("[^ -~]|[ ]", "").toLowerCase(Locale.ENGLISH);
|
||||
cardsByClasses.put(className, card);
|
||||
});
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2270,6 +2270,9 @@ public class VerifyCardDataTest {
|
|||
// ref card
|
||||
System.out.println();
|
||||
MtgJsonCard ref = MtgJsonService.card(card.getName());
|
||||
if (ref == null) {
|
||||
ref = MtgJsonService.cardByClassName(foundClassName);
|
||||
}
|
||||
if (ref != null) {
|
||||
System.out.println("ref: " + ref.getNameAsFace() + " " + ref.manaCost);
|
||||
System.out.println(ref.text);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue