From 9c15984db0c99f6b607e7fec28e4d1b76adbac7c Mon Sep 17 00:00:00 2001 From: nicol Date: Mon, 16 Dec 2024 17:01:00 +0100 Subject: [PATCH] fix scryfall provider defense and mtgquery builder --- .../magic/api/criterias/AbstractQueryBuilder.java | 4 ++++ .../builders/ScryfallCriteriaBuilder.java | 14 +++++++------- .../magic/api/providers/impl/ScryFallProvider.java | 11 +++++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/magic/api/criterias/AbstractQueryBuilder.java b/src/main/java/org/magic/api/criterias/AbstractQueryBuilder.java index f94868ab2..5b5cf9447 100644 --- a/src/main/java/org/magic/api/criterias/AbstractQueryBuilder.java +++ b/src/main/java/org/magic/api/criterias/AbstractQueryBuilder.java @@ -32,6 +32,10 @@ public T build(List crits) { @Override public Object getValueFor(U object) { + if (object==null) + return null; + + if(registry.get(object.getClass())!=null) return registry.get(object.getClass()).marshal(object); diff --git a/src/main/java/org/magic/api/criterias/builders/ScryfallCriteriaBuilder.java b/src/main/java/org/magic/api/criterias/builders/ScryfallCriteriaBuilder.java index 74c820a56..fecd41830 100644 --- a/src/main/java/org/magic/api/criterias/builders/ScryfallCriteriaBuilder.java +++ b/src/main/java/org/magic/api/criterias/builders/ScryfallCriteriaBuilder.java @@ -12,34 +12,34 @@ public String build(MTGCrit... crits) { var temp = new StringBuilder(); - + for(MTGCrit c : crits) { + var separator =":"; + if(c.getType()==Boolean.class) { if(c.getFirst().toString().equals("true")) - temp.append("is:").append(c.getAtt()); + temp.append(" is:").append(c.getAtt()); else - temp.append("not:").append(c.getAtt()); + temp.append(" not:").append(c.getAtt()); } else if(c.getType()==Integer.class) { - var separator =";"; - switch(c.getOperator()) { case GREATER: separator=">";break; case GREATER_EQ: separator=">=";break; case LOWER: separator="<";break; case LOWER_EQ: separator="<=";break; + case NOT : separator="!=";break; default : separator=":";break; } temp.append(c.getAtt()).append(separator).append(c.getFirst()); - } else { - temp.append(c.getAtt()).append(":").append(c.getFirst()); + temp.append(c.getAtt()).append(separator).append(getValueFor(c.getFirst())); } temp.append(" "); } diff --git a/src/main/java/org/magic/api/providers/impl/ScryFallProvider.java b/src/main/java/org/magic/api/providers/impl/ScryFallProvider.java index 84df05020..88d416fe2 100644 --- a/src/main/java/org/magic/api/providers/impl/ScryFallProvider.java +++ b/src/main/java/org/magic/api/providers/impl/ScryFallProvider.java @@ -46,6 +46,7 @@ public class ScryFallProvider extends AbstractCardsProvider { + private static final String DEFENSE = "defense"; private static final String GAMES = "games"; private static final String RELEASED_AT = "released_at"; private static final String IMAGE_URIS = "image_uris"; @@ -280,6 +281,9 @@ private List execute(RequestBuilder q) throws IOException { private RequestBuilder createQuery(String q) { + + logger.info("executing query {}", q); + return RequestBuilder.build().setClient(URLTools.newClient()).url(BASE_URI+"/cards/search").get() .addContent("unique","prints") .addContent("include_extras",getString("EXTRA")) @@ -319,7 +323,6 @@ protected List loadQueryableAttributs() { { arr.add(new QueryAttribute(s,Boolean.class)); } - arr.add(new QueryAttribute(COLOR, EnumColors.class)); arr.add(new QueryAttribute(COLOR_IDENTITY, EnumColors.class)); @@ -415,7 +418,7 @@ private MTGCard generateCard(JsonObject obj, boolean loadMeld) throws ExecutionE mc.setWatermarks(readAsString(obj,"watermark")); mc.setText(readAsString(obj,"oracle_text")); mc.setCost(readAsString(obj,MANA_COST)); - mc.setDefense(readAsInt(obj, "defense")); + mc.setDefense(readAsInt(obj, DEFENSE)); mc.setMkmId(readAsInt(obj,"cardmarket_id")); mc.setTcgPlayerId(readAsInt(obj,"tcgplayer_id")); mc.setPower(readAsString(obj,POWER)); @@ -520,6 +523,10 @@ private void overrideCardFaceData(MTGCard mc, JsonObject obj,String side) mc.setFlavor(readAsString(obj,"flavor_text")); + if(obj.get(DEFENSE)!=null) + mc.setDefense(obj.get(DEFENSE).getAsInt()); + + if(obj.get(COLORS)!=null) { mc.getColors().clear();