allow card name to be specified as value of requires_card_code property, if specified it will load card implementation from the specified card
parent
f6af3657a5
commit
bfbfa96bac
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue