Skip to content

Commit

Permalink
fix scryfall provider defense and mtgquery builder
Browse files Browse the repository at this point in the history
  • Loading branch information
nicol authored and nicol committed Dec 16, 2024
1 parent 22ef5ee commit 9c15984
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public T build(List<MTGCrit> crits) {
@Override
public <U> Object getValueFor(U object)
{
if (object==null)
return null;


if(registry.get(object.getClass())!=null)
return registry.get(object.getClass()).marshal(object);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ");
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/magic/api/providers/impl/ScryFallProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -280,6 +281,9 @@ private List<MTGCard> 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"))
Expand Down Expand Up @@ -319,7 +323,6 @@ protected List<QueryAttribute> loadQueryableAttributs() {
{
arr.add(new QueryAttribute(s,Boolean.class));
}


arr.add(new QueryAttribute(COLOR, EnumColors.class));
arr.add(new QueryAttribute(COLOR_IDENTITY, EnumColors.class));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 9c15984

Please sign in to comment.