*Removed ColorIdentity field from ICardCharacteristics,CardRules and scripts.

*Added experimental Oracle Color Identity parser.
This commit is contained in:
Hellfish
2013-04-01 18:13:42 +00:00
parent 7811880919
commit 91fb2a8f8c
8 changed files with 48 additions and 31 deletions

View File

@@ -29,7 +29,6 @@ final class CardFace implements ICardFace {
private CardType type = null;
private ManaCost manaCost = ManaCost.NO_COST;
private ColorSet color = null;
private ColorSet colorIdentity = null;
private String oracleText = null;
private int iPower = -1;
@@ -59,15 +58,7 @@ final class CardFace implements ICardFace {
@Override public CardType getType() { return this.type; }
@Override public ManaCost getManaCost() { return this.manaCost; }
@Override public ColorSet getColor() { return this.color; }
@Override
public ColorSet getColorIdentity() {
if(this.colorIdentity != null)
return this.colorIdentity;
return this.color;
}
// these are raw and unparsed used for Card creation
@Override public Iterable<String> getKeywords() { return keywords; }
@Override public Iterable<String> getAbilities() { return abilities; }
@@ -86,7 +77,6 @@ final class CardFace implements ICardFace {
public void setType(CardType type0) { this.type = type0; }
public void setManaCost(ManaCost manaCost0) { this.manaCost = manaCost0; }
public void setColor(ColorSet color0) { this.color = color0; }
public void setColorIdentity(ColorSet color0) { this.colorIdentity = color0; }
public void setOracleText(String text) { this.oracleText = text; }
public void setInitialLoyalty(int value) { this.initialLoyalty = value; }

View File

@@ -23,6 +23,7 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import forge.CardColor;
import forge.card.mana.ManaCost;
/**
@@ -39,6 +40,8 @@ public final class CardRules implements ICardCharacteristics {
private final Map<String, CardInSet> setsPrinted = new TreeMap<String, CardInSet>(String.CASE_INSENSITIVE_ORDER);
private CardAiHints aiHints;
private ColorSet colorIdentity = null;
public CardRules(ICardFace[] faces, CardSplitType altMode, CardAiHints cah, Map<String, CardInSet> sets) {
splitType = altMode;
@@ -57,6 +60,49 @@ public final class CardRules implements ICardCharacteristics {
System.err.println(getName() + " was not assigned any set.");
setsPrinted.put(CardEdition.UNKNOWN.getCode(), new CardInSet(CardRarity.Common, 1) );
}
//Calculate Color Identity
byte colMask = calculateColorIdentity(mainPart);
if(otherPart != null)
{
colMask |= calculateColorIdentity(otherPart);
}
colorIdentity = ColorSet.fromMask(colMask);
}
private byte calculateColorIdentity(ICardFace face)
{
byte res = face.getManaCost() == null ? 0 : face.getManaCost().getColorProfile();
boolean isReminder = false;
boolean isSymbol = false;
for(char c : face.getOracleText().toCharArray()) {
switch(c)
{
case('('): isReminder = true; break;
case(')'): isReminder = false; break;
case('{'): isSymbol = true; break;
case('}'): isSymbol = false; break;
default:
if(isSymbol && !isReminder) {
switch(c)
{
case('W'): res |= MagicColor.WHITE; break;
case('U'): res |= MagicColor.BLUE; break;
case('B'): res |= MagicColor.BLACK; break;
case('R'): res |= MagicColor.RED; break;
case('G'): res |= MagicColor.GREEN; break;
}
}
else
{
continue;
}
break;
}
}
return res;
}
public boolean isTraditional() {
@@ -178,16 +224,8 @@ public final class CardRules implements ICardCharacteristics {
return null;
}
@Override
public ColorSet getColorIdentity() {
if(this.otherPart != null)
{
return ColorSet.fromMask(mainPart.getColorIdentity().getColor() | otherPart.getColorIdentity().getColor());
}
else
{
return mainPart.getColorIdentity();
}
return colorIdentity;
}
}

View File

@@ -138,12 +138,6 @@ public class CardRulesReader {
ColorSet newCol = ColorSet.fromNames(value.split(","));
this.faces[this.curFace].setColor(newCol);
}
else if ("ColorIdentity".equals(key)) {
// This is forge.card.CardColor not forge.CardColor.
// Why do we have two classes with the same name?
ColorSet newCol = ColorSet.fromNames(value.split(","));
this.faces[this.curFace].setColorIdentity(newCol);
}
break;
case 'D':

View File

@@ -7,7 +7,6 @@ public interface ICardCharacteristics {
CardType getType();
ManaCost getManaCost();
ColorSet getColor();
ColorSet getColorIdentity();
int getIntPower();
int getIntToughness();