Added downloading and displaying emblem images

This commit is contained in:
magenoxx 2012-06-13 09:48:10 +04:00
parent 09bd74f26e
commit e34ee2e7f6
10 changed files with 75 additions and 23 deletions

View file

@ -1,8 +1,9 @@
package org.mage.plugins.card.dl.sources; package org.mage.plugins.card.dl.sources;
import org.mage.plugins.card.utils.CardImageUtils;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.mage.plugins.card.utils.CardImageUtils;
/** /**
* *
@ -15,6 +16,7 @@ public class MagicCardsImageSource implements CardImageSource {
{ {
put("AVR", "avacyn-restored"); put("AVR", "avacyn-restored");
put("DDI", "duel-decks-venser-vs-koth");
put("DKA", "dark-ascension"); put("DKA", "dark-ascension");
put("ISD", "innistrad"); put("ISD", "innistrad");
put("DDH", "duel-decks-ajani-vs-nicol-bolas"); put("DDH", "duel-decks-ajani-vs-nicol-bolas");
@ -76,7 +78,7 @@ public class MagicCardsImageSource implements CardImageSource {
@Override @Override
public String generateTokenUrl(String name, String set) { public String generateTokenUrl(String name, String set) {
String _name = name.replaceAll(" ", "-").toLowerCase(); String _name = name.replaceAll(" ", "-").replace(",", "").toLowerCase();
String _set = "not-supported-set"; String _set = "not-supported-set";
if (setNameReplacement.containsKey(set)) { if (setNameReplacement.containsKey(set)) {
_set = setNameReplacement.get(set); _set = setNameReplacement.get(set);

View file

@ -337,7 +337,11 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
String set = params[2].substring(4); String set = params[2].substring(4);
CardInfo card = new CardInfo(params[3], set, 0, 0, true); CardInfo card = new CardInfo(params[3], set, 0, 0, true);
list.add(card); list.add(card);
} } else if (params[1].toLowerCase().equals("generate") && params[2].startsWith("EMBLEM:")) {
String set = params[2].substring(7);
CardInfo card = new CardInfo("Emblem " + params[3], set, 0, 0, true);
list.add(card);
}
} else { } else {
log.error("wrong format for image urls: " + line); log.error("wrong format for image urls: " + line);
} }

View file

@ -146,10 +146,11 @@ public class CardImageUtils {
public static String getImagePath(CardInfo card, boolean withCollector, String imagesPath) { public static String getImagePath(CardInfo card, boolean withCollector, String imagesPath) {
String type = card.getType() != 0 ? " " + Integer.toString(card.getType()) : ""; String type = card.getType() != 0 ? " " + Integer.toString(card.getType()) : "";
String name = card.getName();
if (withCollector) { if (withCollector) {
return getImageDir(card, imagesPath) + File.separator + card.getName() + "." + card.getCollectorId() + ".full.jpg"; return getImageDir(card, imagesPath) + File.separator + name + "." + card.getCollectorId() + ".full.jpg";
} else { } else {
return getImageDir(card, imagesPath) + File.separator + card.getName() + type + ".full.jpg"; return getImageDir(card, imagesPath) + File.separator + name + type + ".full.jpg";
} }
} }
} }

View file

@ -1,14 +1,19 @@
|Generate|TOK:AVR|Angel| |Generate|EMBLEM:AVR|Tamiyo, the Moon Sage|
|Generate|TOK:AVR|Human 1|
|Generate|TOK:AVR|Spirit 1| |Generate|TOK:AVR|Angel|
|Generate|TOK:AVR|Spirit 2| |Generate|TOK:AVR|Human 1|
|Generate|TOK:AVR|Demon| |Generate|TOK:AVR|Spirit 1|
|Generate|TOK:AVR|Zombie| |Generate|TOK:AVR|Spirit 2|
|Generate|TOK:AVR|Human 2| |Generate|TOK:AVR|Demon|
|Generate|TOK:AVR|Zombie|
|Generate|TOK:DKA|Human| |Generate|TOK:AVR|Human 2|
|Generate|TOK:DKA|Vampire|
|Generate|EMBLEM:DDI|Venser, the Sojourner|
|Generate|EMBLEM:DDI|Koth of the Hammer|
|Generate|TOK:DKA|Human|
|Generate|TOK:DKA|Vampire|
|Generate|TOK:ISD|Angel| |Generate|TOK:ISD|Angel|
|Generate|TOK:ISD|Spirit| |Generate|TOK:ISD|Spirit|
|Generate|TOK:ISD|Homunculus| |Generate|TOK:ISD|Homunculus|

View file

@ -56,6 +56,6 @@ leg=lg
ptk=p3k ptk=p3k
gur=guru gur=guru
mpr=mprp mpr=mprp
ignore.urls=TOK ignore.urls=TOK,EMBLEM
# sets ordered by release time (newest goes first) # sets ordered by release time (newest goes first)
token.lookup.order=NPH,MBS,SOM,M11,ROE,PVC,WWK,ZEN,M10,GVL,ARB,DVD,CFX,JVC,ALA,EVE,SHM,EVG,MOR,LRW,10E,CLS,CHK token.lookup.order=AVR,DDI,DKA,ISD,M12,NPH,MBS,SOM,M11,ROE,PVC,WWK,ZEN,M10,GVL,ARB,DVD,CFX,JVC,ALA,EVE,SHM,EVG,MOR,LRW,10E,CLS,CHK

View file

@ -157,11 +157,11 @@ public class CardView extends SimpleCardView {
this.rules = ((PermanentToken) card).getRules(); this.rules = ((PermanentToken) card).getRules();
this.type = ((PermanentToken)card).getToken().getTokenType(); this.type = ((PermanentToken)card).getToken().getTokenType();
} }
if (name.equals("") && card instanceof StackAbility) { if (this.rarity == null && card instanceof StackAbility) {
StackAbility stackAbility = (StackAbility)card; StackAbility stackAbility = (StackAbility)card;
if (stackAbility.getZone().equals(Constants.Zone.COMMAND)) { if (stackAbility.getZone().equals(Constants.Zone.COMMAND)) {
this.name = "Emblem";
this.rarity = Rarity.NA; this.rarity = Rarity.NA;
this.expansionSetCode = stackAbility.getExpansionSetCode();
this.rules = new ArrayList<String>(); this.rules = new ArrayList<String>();
this.rules.add(stackAbility.getRule()); this.rules.add(stackAbility.getRule());
} }

View file

@ -37,6 +37,7 @@ import mage.game.ExileZone;
import mage.game.Game; import mage.game.Game;
import mage.game.GameState; import mage.game.GameState;
import mage.game.combat.CombatGroup; import mage.game.combat.CombatGroup;
import mage.game.command.CommandObject;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.stack.Spell; import mage.game.stack.Spell;
import mage.game.stack.StackAbility; import mage.game.stack.StackAbility;
@ -44,7 +45,10 @@ import mage.game.stack.StackObject;
import mage.players.Player; import mage.players.Player;
import java.io.Serializable; import java.io.Serializable;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/** /**
* *
@ -89,6 +93,15 @@ public class GameView implements Serializable {
} else if (object != null) { } else if (object != null) {
StackAbility stackAbility = ((StackAbility)object); StackAbility stackAbility = ((StackAbility)object);
stackAbility.newId(); stackAbility.newId();
MageObject emblem = game.getEmblem(stackAbility.getSourceId());
if (emblem != null) {
Card sourceCard = game.getCard(((CommandObject)emblem).getSourceId());
if (sourceCard != null) {
stackAbility.setName("Emblem " + sourceCard.getName());
stackAbility.setExpansionSetCode(sourceCard.getExpansionSetCode());
}
}
stack.put(stackObject.getId(), new CardView(stackAbility)); stack.put(stackObject.getId(), new CardView(stackAbility));
} }
} }

View file

@ -81,6 +81,7 @@ public interface Game extends MageItem, Serializable {
public void setCustomData(Object data); public void setCustomData(Object data);
public GameOptions getOptions(); public GameOptions getOptions();
public MageObject getObject(UUID objectId); public MageObject getObject(UUID objectId);
public MageObject getEmblem(UUID objectId);
public UUID getControllerId(UUID objectId); public UUID getControllerId(UUID objectId);
public Permanent getPermanent(UUID permanentId); public Permanent getPermanent(UUID permanentId);
public Card getCard(UUID cardId); public Card getCard(UUID cardId);

View file

@ -266,6 +266,18 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
return object; return object;
} }
@Override
public MageObject getEmblem(UUID objectId) {
if (objectId == null)
return null;
for (CommandObject commandObject : state.getCommand()) {
if (commandObject.getId().equals(objectId)) {
return commandObject;
}
}
return null;
}
@Override @Override
public UUID getControllerId(UUID objectId) { public UUID getControllerId(UUID objectId) {
if (objectId == null) { if (objectId == null) {

View file

@ -68,6 +68,8 @@ public class StackAbility implements StackObject, Ability {
private Ability ability; private Ability ability;
private UUID controllerId; private UUID controllerId;
private String name = "";
private String expansionSetCode;
public StackAbility(Ability ability, UUID controllerId) { public StackAbility(Ability ability, UUID controllerId) {
this.ability = ability; this.ability = ability;
@ -77,6 +79,8 @@ public class StackAbility implements StackObject, Ability {
public StackAbility(final StackAbility spell) { public StackAbility(final StackAbility spell) {
this.ability = spell.ability.copy(); this.ability = spell.ability.copy();
this.controllerId = spell.controllerId; this.controllerId = spell.controllerId;
this.name = spell.name;
this.expansionSetCode = spell.expansionSetCode;
} }
@Override @Override
@ -101,8 +105,12 @@ public class StackAbility implements StackObject, Ability {
@Override @Override
public String getName() { public String getName() {
return ""; return name;
} }
public String getExpansionSetCode() {
return expansionSetCode;
}
@Override @Override
public List<CardType> getCardType() { public List<CardType> getCardType() {
@ -276,7 +284,13 @@ public class StackAbility implements StackObject, Ability {
} }
@Override @Override
public void setName(String name) { } public void setName(String name) {
this.name = name;
}
public void setExpansionSetCode(String expansionSetCode) {
this.expansionSetCode = expansionSetCode;
}
@Override @Override
public void adjustCosts(Ability ability, Game game) {} public void adjustCosts(Ability ability, Game game) {}