allow card name to be specified as value of requires_card_code property, if specified it will load card implementation from the specified card

master
melvin 2012-10-30 13:32:29 +08:00
parent f6af3657a5
commit bfbfa96bac
3 changed files with 9 additions and 22 deletions

View File

@ -73,18 +73,13 @@ public class CardDefinitions {
setProperty(cardDefinition, key, content.getProperty(key));
}
//add card specific code
if (cardDefinition.hasCode()) {
addCardSpecificCode(cardDefinition);
}
return cardDefinition;
}
//link to companion object containing static variables
private static void addCardSpecificCode(final MagicCardDefinition cardDefinition) {
static void addCardSpecificCode(final MagicCardDefinition cardDefinition, final String cardName) {
try { //reflection
final Class c = Class.forName("magic.card." + cardDefinition.getCanonicalName());
final Class c = Class.forName("magic.card." + getCanonicalName(cardName));
for (final Field field : c.getFields()) {
final MagicChangeCardDefinition ccd = (MagicChangeCardDefinition)field.get(null);
ccd.change(cardDefinition);
@ -96,6 +91,10 @@ public class CardDefinitions {
}
}
private static String getCanonicalName(String fullName) {
return fullName.replaceAll("[^A-Za-z0-9]", "_");
}
private static void loadCardDefinition(final File file) {
try {
final MagicCardDefinition cdef = prop2carddef(FileIO.toProp(file));

View File

@ -168,7 +168,8 @@ public enum CardProperty {
},
REQUIRES_CARD_CODE() {
void setProperty(final MagicCardDefinition card, final String value) {
card.setHasCode();
final String cardName = !value.isEmpty() ? value : card.getFullName();
CardDefinitions.addCardSpecificCode(card, cardName);
}
};

View File

@ -75,7 +75,6 @@ public class MagicCardDefinition {
private int score=-1; // not initialized
private MagicRarity rarity;
private boolean token;
private boolean hasCode;
private int typeFlags;
private EnumSet<MagicSubType> subTypeFlags = EnumSet.noneOf(MagicSubType.class);
private int colorFlags;
@ -144,22 +143,10 @@ public class MagicCardDefinition {
return fullName;
}
public String getCanonicalName() {
return fullName.replaceAll("[^A-Za-z0-9]", "_");
}
public void setFullName(final String name) {
fullName = name;
}
public void setHasCode() {
hasCode = true;
}
public boolean hasCode() {
return hasCode;
}
public void setIndex(final int index) {
this.index=index;
}