mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
removed redundant imports
CardPrinted now supports getImageFinelame() SetInfoUtil refactored, its dependencies updated
This commit is contained in:
@@ -6,7 +6,6 @@ import java.util.Map;
|
||||
|
||||
import net.slightlymagic.braids.util.UtilFunctions;
|
||||
import forge.card.cardFactory.CardFactoryInterface;
|
||||
import forge.card.cardFactory.LazyCardFactory;
|
||||
import forge.card.cardFactory.PreloadingCardFactory;
|
||||
import forge.card.mana.ManaPool;
|
||||
import forge.card.trigger.TriggerHandler;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package forge;
|
||||
|
||||
import forge.card.CardPrinted;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.SpellAbilityList;
|
||||
@@ -11,10 +12,13 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* <p>CardUtil class.</p>
|
||||
@@ -489,80 +493,52 @@ public final class CardUtil {
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String buildFilename(final Card card) {
|
||||
File path = null;
|
||||
if (card.isToken() && !card.isCopiedToken()) {
|
||||
path = ForgeProps.getFile(NewConstants.IMAGE_TOKEN);
|
||||
} else {
|
||||
path = ForgeProps.getFile(NewConstants.IMAGE_BASE);
|
||||
}
|
||||
boolean token = card.isToken() && !card.isCopiedToken();
|
||||
return buildFilename(card.getName(), card.getCurSetCode(), card.getRandomPicture(), token);
|
||||
}
|
||||
|
||||
StringBuilder sbKey = new StringBuilder();
|
||||
public static String buildFilename(final CardPrinted card) {
|
||||
return buildFilename(card.getName(), card.getSet(), card.getArtIndex(), false);
|
||||
}
|
||||
|
||||
private static String buildFilename(final String cardName, final String setName,
|
||||
final int artIndex, final boolean isToken)
|
||||
{
|
||||
File path = ForgeProps.getFile(isToken ? NewConstants.IMAGE_TOKEN : NewConstants.IMAGE_BASE);
|
||||
String nn = artIndex > 0 ? Integer.toString(artIndex) : "";
|
||||
String cleanCardName = GuiDisplayUtil.cleanString(cardName);
|
||||
|
||||
File f = null;
|
||||
if (!card.getCurSetCode().equals("")) {
|
||||
String nn = "";
|
||||
if (card.getRandomPicture() > 0) {
|
||||
nn = Integer.toString(card.getRandomPicture());
|
||||
}
|
||||
if (StringUtils.isNotBlank(setName)) {
|
||||
String mwsCardName = GuiDisplayUtil.cleanStringMWS(cardName);
|
||||
|
||||
//First try 3 letter set code with MWS filename format
|
||||
sbKey.append(card.getCurSetCode() + "/");
|
||||
sbKey.append(GuiDisplayUtil.cleanStringMWS(card.getName()) + nn + ".full");
|
||||
|
||||
f = new File(path, sbKey.toString() + ".jpg");
|
||||
if (f.exists()) {
|
||||
return sbKey.toString();
|
||||
}
|
||||
|
||||
sbKey = new StringBuilder();
|
||||
//First, try 3 letter set code with MWS filename format
|
||||
String mwsSet3 = String.format("%s/%s%s.full", setName, mwsCardName, nn);
|
||||
f = new File(path, mwsSet3 + ".jpg");
|
||||
if (f.exists()) { return mwsSet3; }
|
||||
|
||||
//Second, try 2 letter set code with MWS filename format
|
||||
sbKey.append(SetInfoUtil.getSetCode2_SetCode3(card.getCurSetCode()) + "/");
|
||||
sbKey.append(GuiDisplayUtil.cleanStringMWS(card.getName()) + nn + ".full");
|
||||
|
||||
f = new File(path, sbKey.toString() + ".jpg");
|
||||
if (f.exists()) {
|
||||
return sbKey.toString();
|
||||
}
|
||||
|
||||
sbKey = new StringBuilder();
|
||||
String mwsSet2 = String.format("%s/%s%s.full", SetInfoUtil.getCode2ByCode(setName), mwsCardName, nn);
|
||||
f = new File(path, mwsSet2 + ".jpg");
|
||||
if (f.exists()) { return mwsSet2; }
|
||||
|
||||
//Third, try 3 letter set code with Forge filename format
|
||||
sbKey.append(card.getCurSetCode() + "/");
|
||||
sbKey.append(GuiDisplayUtil.cleanString(card.getName()) + nn);
|
||||
|
||||
f = new File(path, sbKey.toString() + ".jpg");
|
||||
if (f.exists()) {
|
||||
return sbKey.toString();
|
||||
}
|
||||
|
||||
sbKey = new StringBuilder();
|
||||
|
||||
String forgeSet3 = String.format("%s/%s%s", setName, cleanCardName, nn);
|
||||
f = new File(path, forgeSet3 + ".jpg");
|
||||
if (f.exists()) { return forgeSet3; }
|
||||
}
|
||||
|
||||
//Last, give up with set images, go with the old picture type
|
||||
sbKey.append(GuiDisplayUtil.cleanString(card.getImageName()));
|
||||
if (card.getRandomPicture() > 1) {
|
||||
sbKey.append(card.getRandomPicture());
|
||||
}
|
||||
String forgePlain = String.format("%s%s", cleanCardName, nn);
|
||||
|
||||
f = new File(path, sbKey.toString() + ".jpg");
|
||||
if (f.exists()) {
|
||||
return sbKey.toString();
|
||||
}
|
||||
f = new File(path, forgePlain + ".jpg");
|
||||
if (f.exists()) { return forgePlain; }
|
||||
|
||||
sbKey = new StringBuilder();
|
||||
|
||||
//Really last-ditch effort, forget the picture number
|
||||
sbKey.append(GuiDisplayUtil.cleanString(card.getImageName()));
|
||||
|
||||
f = new File(path, sbKey.toString() + ".jpg");
|
||||
if (f.exists()) {
|
||||
return sbKey.toString();
|
||||
}
|
||||
// give up with art index
|
||||
f = new File(path, cleanCardName + ".jpg");
|
||||
if (f.exists()) { return cleanCardName; }
|
||||
|
||||
//if still no file, download if option enabled?
|
||||
|
||||
return "none";
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
@@ -389,7 +390,7 @@ public class Gui_DeckEditor extends JFrame implements CardContainer, DeckDisplay
|
||||
String SC = "";
|
||||
|
||||
if (!(searchSetCombo.getSelectedItem().toString().equals(""))) {
|
||||
SC = SetInfoUtil.getSetCode3_SetName(searchSetCombo.getSelectedItem().toString());
|
||||
SC = SetInfoUtil.getCode3ByName(searchSetCombo.getSelectedItem().toString());
|
||||
|
||||
boolean result = false;
|
||||
|
||||
@@ -959,8 +960,11 @@ public class Gui_DeckEditor extends JFrame implements CardContainer, DeckDisplay
|
||||
|
||||
searchSetCombo.removeAllItems();
|
||||
searchSetCombo.addItem("");
|
||||
for (int i = 0; i < SetInfoUtil.getSetNameList().size(); i++)
|
||||
searchSetCombo.addItem(SetInfoUtil.getSetNameList().get(i));
|
||||
List<String> allSetsNames = SetInfoUtil.getNameList();
|
||||
for (String s : allSetsNames) {
|
||||
searchSetCombo.addItem(s);
|
||||
}
|
||||
|
||||
this.getContentPane().add(searchSetCombo, "wmin 150, grow");
|
||||
|
||||
this.getContentPane().add(statsLabel2, "cell 0 4");
|
||||
|
||||
@@ -394,7 +394,7 @@ public class Gui_DownloadSetPictures_LQ extends DefaultBoundedRangeModel impleme
|
||||
for (int j = 0; j < cSetInfo.size(); j++) {
|
||||
c.setCurSetCode(cSetInfo.get(j).Code);
|
||||
String SC3 = c.getCurSetCode();
|
||||
String SC2 = SetInfoUtil.getSetCode2_SetCode3(c.getCurSetCode());
|
||||
String SC2 = SetInfoUtil.getCode2ByCode(c.getCurSetCode());
|
||||
|
||||
int n = 0;
|
||||
if (cSetInfo.get(j).PicCount > 0) {
|
||||
|
||||
@@ -402,7 +402,7 @@ public class Gui_MigrateLocalMWSSetPictures_HQ extends DefaultBoundedRangeModel
|
||||
for (int j = 0; j < cSetInfo.size(); j++) {
|
||||
c.setCurSetCode(cSetInfo.get(j).Code);
|
||||
String SC3 = c.getCurSetCode();
|
||||
String SC2 = SetInfoUtil.getSetCode2_SetCode3(c.getCurSetCode());
|
||||
String SC2 = SetInfoUtil.getCode2ByCode(c.getCurSetCode());
|
||||
|
||||
int n = 0;
|
||||
if (cSetInfo.get(j).PicCount > 0) {
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
package forge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.slightlymagic.maxmtg.Predicate;
|
||||
|
||||
import forge.card.CardSet;
|
||||
|
||||
/**
|
||||
* <p>SetInfoUtil class.</p>
|
||||
@@ -11,7 +18,8 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class SetInfoUtil {
|
||||
/** Constant <code>setData</code> */
|
||||
private static ArrayList<HashMap<String, String>> setData = new ArrayList<HashMap<String, String>>();
|
||||
private static HashMap<String, CardSet> setsByCode = new HashMap<String, CardSet>();
|
||||
private static List<CardSet> allSets = new ArrayList<CardSet>();
|
||||
|
||||
/**
|
||||
* <p>loadSetData.</p>
|
||||
@@ -19,57 +27,51 @@ public class SetInfoUtil {
|
||||
private static void loadSetData() {
|
||||
ArrayList<String> fData = FileUtil.readFile("res/blockdata/setdata.txt");
|
||||
|
||||
if (fData.size() > 0) {
|
||||
for (int i = 0; i < fData.size(); i++) {
|
||||
String s = fData.get(i);
|
||||
if (s.length() > 5) {
|
||||
HashMap<String, String> sm = new HashMap<String, String>();
|
||||
for (String s : fData) {
|
||||
if (s.length() < 6) { continue; }
|
||||
|
||||
String ss[] = s.split("\\|");
|
||||
for (int j = 0; j < ss.length; j++) {
|
||||
String kv[] = ss[j].split(":");
|
||||
sm.put(kv[0], kv[1]);
|
||||
}
|
||||
String[] sParts = s.trim().split("\\|");
|
||||
String code = null, code2 = null, name = null;
|
||||
|
||||
setData.add(sm);
|
||||
int index = -1;
|
||||
String alias = null;
|
||||
for (String sPart : sParts) {
|
||||
String[] kv = sPart.split(":", 2);
|
||||
String key = kv[0].toLowerCase();
|
||||
if ("code3".equals(key)) {
|
||||
code = kv[1];
|
||||
} else if ("code2".equals(key)) {
|
||||
code2 = kv[1];
|
||||
} else if ("name".equals(key)) {
|
||||
name = kv[1];
|
||||
} else if ("index".equals(key)) {
|
||||
index = Integer.parseInt(kv[1]);
|
||||
} else if ("alias".equals(key)) {
|
||||
alias = kv[1];
|
||||
}
|
||||
}
|
||||
|
||||
CardSet set = new CardSet(index, name, code, code2);
|
||||
setsByCode.put(code, set);
|
||||
if (alias != null) { setsByCode.put(alias, set); }
|
||||
allSets.add(set);
|
||||
}
|
||||
Collections.sort(allSets);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getSetCode2List.</p>
|
||||
*
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static ArrayList<String> getSetCode2List() {
|
||||
ArrayList<String> scl = new ArrayList<String>();
|
||||
|
||||
if (setData.size() == 0)
|
||||
loadSetData();
|
||||
|
||||
for (int i = 0; i < setData.size(); i++)
|
||||
scl.add(setData.get(i).get("Code2"));
|
||||
|
||||
return scl;
|
||||
public static CardSet getSetByCode(final String code) {
|
||||
if (setsByCode.isEmpty()) { loadSetData(); }
|
||||
return setsByCode.get(code);
|
||||
}
|
||||
public static CardSet getSetByCodeOrThrow(final String code) {
|
||||
if (setsByCode.isEmpty()) { loadSetData(); }
|
||||
CardSet set = setsByCode.get(code);
|
||||
if (null == set) { throw new RuntimeException(String.format("Set with code '%s' not found", code)); }
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getSetCode3List.</p>
|
||||
*
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static ArrayList<String> getSetCode3List() {
|
||||
ArrayList<String> scl = new ArrayList<String>();
|
||||
|
||||
if (setData.size() == 0)
|
||||
loadSetData();
|
||||
|
||||
for (int i = 0; i < setData.size(); i++)
|
||||
scl.add(setData.get(i).get("Code3"));
|
||||
|
||||
return scl;
|
||||
public static List<String> getCodeList() {
|
||||
if (setsByCode.isEmpty()) { loadSetData(); }
|
||||
return new ArrayList<String>(setsByCode.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,101 +79,26 @@ public class SetInfoUtil {
|
||||
*
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static ArrayList<String> getSetNameList() {
|
||||
ArrayList<String> snl = new ArrayList<String>();
|
||||
public static List<String> getNameList() {
|
||||
if (setsByCode.isEmpty()) { loadSetData(); }
|
||||
|
||||
if (setData.size() == 0)
|
||||
loadSetData();
|
||||
|
||||
for (int i = 0; i < setData.size(); i++)
|
||||
snl.add(setData.get(i).get("Name"));
|
||||
|
||||
return snl;
|
||||
return Predicate.getTrue(CardSet.class).select(allSets, CardSet.fn1, CardSet.fnGetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getSetCode2_SetName.</p>
|
||||
*
|
||||
* @param SetName a {@link java.lang.String} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String getSetCode2_SetName(String SetName) {
|
||||
if (setData.size() == 0)
|
||||
loadSetData();
|
||||
public static String getCode3ByName(final String setName) {
|
||||
if (setsByCode.isEmpty()) { loadSetData(); }
|
||||
|
||||
for (int i = 0; i < setData.size(); i++)
|
||||
if (setData.get(i).get("Name").equals(SetName))
|
||||
return setData.get(i).get("Code2");
|
||||
for (CardSet s : setsByCode.values()) {
|
||||
if (s.getName().equals(setName)) { return s.getCode(); }
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getSetCode3_SetName.</p>
|
||||
*
|
||||
* @param SetName a {@link java.lang.String} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String getSetCode3_SetName(String SetName) {
|
||||
if (setData.size() == 0)
|
||||
loadSetData();
|
||||
|
||||
for (int i = 0; i < setData.size(); i++)
|
||||
if (setData.get(i).get("Name").equals(SetName))
|
||||
return setData.get(i).get("Code3");
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getSetCode2_SetCode3.</p>
|
||||
*
|
||||
* @param SetCode3 a {@link java.lang.String} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String getSetCode2_SetCode3(String SetCode3) {
|
||||
if (setData.size() == 0)
|
||||
loadSetData();
|
||||
|
||||
for (int i = 0; i < setData.size(); i++)
|
||||
if (setData.get(i).get("Code3").equals(SetCode3))
|
||||
return setData.get(i).get("Code2");
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getSetCode3_SetCode2.</p>
|
||||
*
|
||||
* @param SetCode2 a {@link java.lang.String} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String getSetCode3_SetCode2(String SetCode2) {
|
||||
if (setData.size() == 0)
|
||||
loadSetData();
|
||||
|
||||
for (int i = 0; i < setData.size(); i++)
|
||||
if (setData.get(i).get("Code2").equals(SetCode2))
|
||||
return setData.get(i).get("Code3");
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getSetName_SetCode2.</p>
|
||||
*
|
||||
* @param SetCode2 a {@link java.lang.String} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String getSetName_SetCode2(String SetCode2) {
|
||||
if (setData.size() == 0)
|
||||
loadSetData();
|
||||
|
||||
for (int i = 0; i < setData.size(); i++)
|
||||
if (setData.get(i).get("Code2").equals(SetCode2))
|
||||
return setData.get(i).get("Name");
|
||||
|
||||
return "";
|
||||
public static String getCode2ByCode(final String code) {
|
||||
if (setsByCode.isEmpty()) { loadSetData(); }
|
||||
CardSet set = setsByCode.get(code);
|
||||
return set == null ? "" : set.getCode2();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,15 +107,10 @@ public class SetInfoUtil {
|
||||
* @param SetCode3 a {@link java.lang.String} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String getSetName_SetCode3(String SetCode3) {
|
||||
if (setData.size() == 0)
|
||||
loadSetData();
|
||||
|
||||
for (int i = 0; i < setData.size(); i++)
|
||||
if (setData.get(i).get("Code3").equals(SetCode3))
|
||||
return setData.get(i).get("Name");
|
||||
|
||||
return "";
|
||||
public static String getNameByCode(String code) {
|
||||
if (setsByCode.isEmpty()) { loadSetData(); }
|
||||
CardSet set = setsByCode.get(code);
|
||||
return set == null ? "" : set.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,28 +119,18 @@ public class SetInfoUtil {
|
||||
* @param alSI a {@link java.util.ArrayList} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String getMostRecentSet(ArrayList<SetInfo> alSI) {
|
||||
if (setData.size() == 0)
|
||||
loadSetData();
|
||||
public static String getMostRecentSet(final ArrayList<SetInfo> alSI) {
|
||||
if (setsByCode.isEmpty()) { loadSetData(); }
|
||||
|
||||
int mostRecent = -1;
|
||||
int size = alSI.size();
|
||||
if (size == 0) { return ""; }
|
||||
if (size == 1) { return alSI.get(0).Code; }
|
||||
|
||||
for (SetInfo s : alSI) {
|
||||
for (int j = 0; j < setData.size(); j++) {
|
||||
if (setData.get(j).get("Code3").equals(s.Code)) {
|
||||
if (j > mostRecent) {
|
||||
mostRecent = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
CardSet[] sets = new CardSet[size];
|
||||
for (int i = 0; i < size; i++) { sets[i] = setsByCode.get(alSI.get(i).Code); }
|
||||
Arrays.sort(sets);
|
||||
|
||||
}
|
||||
|
||||
if (mostRecent > -1)
|
||||
return setData.get(mostRecent).get("Code3");
|
||||
|
||||
return "";
|
||||
return sets[sets.length - 1].getCode();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,8 +145,7 @@ public class SetInfoUtil {
|
||||
|
||||
for (int i = 0; i < SetList.size(); i++) {
|
||||
si = SetList.get(i);
|
||||
if (si.Code.equals(SetCode))
|
||||
return si;
|
||||
if (si.Code.equals(SetCode)) { return si; }
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -246,16 +157,10 @@ public class SetInfoUtil {
|
||||
* @param SetCode a {@link java.lang.String} object.
|
||||
* @return a int.
|
||||
*/
|
||||
public static int getSetIndex(String SetCode) {
|
||||
if (setData.size() == 0)
|
||||
loadSetData();
|
||||
|
||||
for (int i = 0; i < setData.size(); i++) {
|
||||
if (setData.get(i).get("Code3").equals(SetCode))
|
||||
return Integer.parseInt(setData.get(i).get("Index"));
|
||||
}
|
||||
|
||||
return 0;
|
||||
public static int getIndexByCode(final String code) {
|
||||
if (setsByCode.isEmpty()) { loadSetData(); }
|
||||
CardSet set = setsByCode.get(code);
|
||||
return set == null ? 0 : set.getIndex();
|
||||
}
|
||||
|
||||
/** Constant <code>blockData</code> */
|
||||
|
||||
@@ -119,8 +119,8 @@ public class TableSorter implements Comparator<Card>, NewConstants {
|
||||
bCom = getValue(b);
|
||||
} else if (column == 7 && col7mod == true)//Set
|
||||
{
|
||||
aCom = SetInfoUtil.getSetIndex(a.getCurSetCode());
|
||||
bCom = SetInfoUtil.getSetIndex(b.getCurSetCode());
|
||||
aCom = SetInfoUtil.getIndexByCode(a.getCurSetCode());
|
||||
bCom = SetInfoUtil.getIndexByCode(b.getCurSetCode());
|
||||
} else if (column == 8)//AI
|
||||
{
|
||||
aCom = getAI(a);
|
||||
|
||||
@@ -4,8 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>CardManaCost class.</p>
|
||||
*
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package forge.card;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import net.slightlymagic.maxmtg.Predicate;
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.CardUtil;
|
||||
|
||||
/**
|
||||
* <p>CardReference class.</p>
|
||||
@@ -27,7 +29,10 @@ public final class CardPrinted implements Comparable<CardPrinted> {
|
||||
private final transient CardRarity rarity; // rarity is given in ctor when set is assigned
|
||||
|
||||
// need this to be sure that different cased names won't break the system (and create uniqie cardref entries)
|
||||
private final transient String _name_lcase;
|
||||
private final transient String nameLcase;
|
||||
|
||||
// image filename is calculated only after someone request it
|
||||
private transient String imageFilename = null;
|
||||
|
||||
// field RO accessors
|
||||
public String getName() { return name; }
|
||||
@@ -36,7 +41,10 @@ public final class CardPrinted implements Comparable<CardPrinted> {
|
||||
public boolean isFoil() { return foiled; }
|
||||
public CardRules getCard() { return card; }
|
||||
public CardRarity getRarity() { return rarity; }
|
||||
|
||||
public String getImageFilename() {
|
||||
if (imageFilename == null) { imageFilename = CardUtil.buildFilename(this); }
|
||||
return imageFilename;
|
||||
}
|
||||
|
||||
// Lambda to get rules for selects from list of printed cards
|
||||
public static final Lambda1<CardRules, CardPrinted> fnGetRules = new Lambda1<CardRules, CardPrinted>() {
|
||||
@@ -44,14 +52,16 @@ public final class CardPrinted implements Comparable<CardPrinted> {
|
||||
};
|
||||
|
||||
// Constructor is private. All non-foiled instances are stored in CardDb
|
||||
private CardPrinted(final CardRules c, final String set, final CardRarity rare, final int index, boolean foil) {
|
||||
private CardPrinted(final CardRules c, final String set, final CardRarity rare,
|
||||
final int index, final boolean foil)
|
||||
{
|
||||
card = c;
|
||||
name = c.getName();
|
||||
cardSet = set;
|
||||
artIndex = index;
|
||||
foiled = foil;
|
||||
rarity = rare;
|
||||
_name_lcase = name.toLowerCase();
|
||||
nameLcase = name.toLowerCase();
|
||||
}
|
||||
|
||||
/* package visibility */
|
||||
@@ -81,7 +91,7 @@ public final class CardPrinted implements Comparable<CardPrinted> {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int code = _name_lcase.hashCode() * 11 + cardSet.hashCode() * 59 + artIndex * 2;
|
||||
int code = nameLcase.hashCode() * 11 + cardSet.hashCode() * 59 + artIndex * 2;
|
||||
if (foiled) { return code + 1; }
|
||||
return code;
|
||||
}
|
||||
@@ -93,13 +103,18 @@ public final class CardPrinted implements Comparable<CardPrinted> {
|
||||
|
||||
public Card toForgeCard() {
|
||||
Card c = AllZone.getCardFactory().getCard(name, null);
|
||||
c.setCurSetCode(getSet());
|
||||
if (c != null) {
|
||||
c.setCurSetCode(getSet());
|
||||
c.setRandomPicture(artIndex);
|
||||
c.setImageFilename(getImageFilename());
|
||||
}
|
||||
// else throw "Unsupported card";
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final CardPrinted o) {
|
||||
int nameCmp = _name_lcase.compareTo(o._name_lcase);
|
||||
int nameCmp = nameLcase.compareTo(o.nameLcase);
|
||||
if (0 != nameCmp) { return nameCmp; }
|
||||
// TODO: compare sets properly
|
||||
return cardSet.compareTo(o.cardSet);
|
||||
@@ -111,9 +126,9 @@ public final class CardPrinted implements Comparable<CardPrinted> {
|
||||
{
|
||||
return new PredicateRarity(value, isEqual);
|
||||
}
|
||||
public static Predicate<CardPrinted> printedInSets(final String[] value)
|
||||
public static Predicate<CardPrinted> printedInSets(final List<String> value, final boolean shouldContain)
|
||||
{
|
||||
return new PredicateSets(value);
|
||||
return new PredicateSets(value, shouldContain);
|
||||
}
|
||||
|
||||
private static class PredicateRarity extends Predicate<CardPrinted> {
|
||||
@@ -132,16 +147,20 @@ public final class CardPrinted implements Comparable<CardPrinted> {
|
||||
}
|
||||
|
||||
private static class PredicateSets extends Predicate<CardPrinted> {
|
||||
private final String[] sets;
|
||||
private final List<String> sets;
|
||||
private final boolean mustContain;
|
||||
@Override public boolean isTrue(final CardPrinted card) {
|
||||
return Arrays.binarySearch(sets, card.rarity) >= 0;
|
||||
return sets.contains(card.cardSet) == mustContain;
|
||||
}
|
||||
public PredicateSets(final String[] wantSets) {
|
||||
sets = wantSets.clone();
|
||||
Arrays.sort(sets);
|
||||
public PredicateSets(final List<String> wantSets, boolean shouldContain) {
|
||||
sets = wantSets; // maybe should make a copy here?
|
||||
mustContain = shouldContain;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-built predicates are stored here to allow their re-usage and easier access from code
|
||||
*/
|
||||
public abstract static class Presets {
|
||||
// Think twice before using these, since rarity is a prop of printed card.
|
||||
public static final Predicate<CardPrinted> isCommon = rarity(true, CardRarity.Common);
|
||||
@@ -149,14 +168,12 @@ public final class CardPrinted implements Comparable<CardPrinted> {
|
||||
public static final Predicate<CardPrinted> isRare = rarity(true, CardRarity.Rare);
|
||||
public static final Predicate<CardPrinted> isMythicRare = rarity(true, CardRarity.MythicRare);
|
||||
public static final Predicate<CardPrinted> isRareOrMythic = Predicate.or(isRare, isMythicRare);
|
||||
|
||||
public static final Predicate<CardPrinted> isSpecial = rarity(true, CardRarity.Special);
|
||||
|
||||
public static final Predicate<CardPrinted> exceptLands = rarity(false, CardRarity.BasicLand);
|
||||
|
||||
// TODO: Update this code on each rotation (or move this list to a file)
|
||||
public static final Predicate<CardPrinted> isStandard = printedInSets(
|
||||
new String[] {"M12", "NPH", "MBS", "SOM", "M11", "ROE", "WWK", "ZEN"});
|
||||
Arrays.asList(new String[] {"M12", "NPH", "MBS", "SOM", "M11", "ROE", "WWK", "ZEN"}), true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,11 @@
|
||||
|
||||
package forge.card;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
//import java.util.Enumeration;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
//import java.util.zip.ZipEntry;
|
||||
//import java.util.zip.ZipFile;
|
||||
|
||||
import forge.card.CardManaCost.ManaParser;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user