mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
CardInSet data moved to CardRules,
picture removed from CardInSet, it's also no longer needed in SetInfos
This commit is contained in:
@@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@@ -80,7 +79,6 @@ final class CardFace implements ICardFace {
|
||||
public final void setColor(ColorSet color0) { this.color = color0; }
|
||||
public final void setOracleText(String text) { this.oracleText = text; }
|
||||
public final void setInitialLoyalty(int value) { this.initialLoyalty = value; }
|
||||
public final Map<String, CardInSet> getSetsData() { return this.setsPrinted; } // reader will add sets here
|
||||
|
||||
public void setPtText(String value) {
|
||||
final int slashPos = value.indexOf('/');
|
||||
@@ -105,7 +103,6 @@ final class CardFace implements ICardFace {
|
||||
|
||||
public void assignMissingFields() { // Most scripts do not specify color explicitly
|
||||
if ( null == oracleText ) { System.err.println(name + " has no Oracle text."); oracleText = ""; }
|
||||
if ( setsPrinted.isEmpty() ) { System.err.println(name + " was not assigned any set."); setsPrinted.put(CardEdition.UNKNOWN.getCode(), new CardInSet(CardRarity.Common, 1, null) ) ; }
|
||||
if ( manaCost == null && color == null ) System.err.println(name + " has neither ManaCost nor Color");
|
||||
if ( color == null ) color = ColorSet.fromManaCost(manaCost);
|
||||
|
||||
@@ -119,14 +116,4 @@ final class CardFace implements ICardFace {
|
||||
}
|
||||
|
||||
|
||||
// This should not be here, but I don't know a better place yet
|
||||
private final Map<String, CardInSet> setsPrinted = new TreeMap<String, CardInSet>(String.CASE_INSENSITIVE_ORDER);
|
||||
@Override public Set<String> getSets() { return this.setsPrinted.keySet(); }
|
||||
@Override public CardInSet getEditionInfo(final String setCode) {
|
||||
final CardInSet result = this.setsPrinted.get(setCode);
|
||||
return result; // if returns null, String.format("Card '%s' was never printed in set '%s'", this.getName(), setCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ package forge.card;
|
||||
public class CardInSet {
|
||||
private final CardRarity rarity;
|
||||
private final int numCopies;
|
||||
private final String url;
|
||||
|
||||
/**
|
||||
* Instantiates a new card in set.
|
||||
@@ -39,10 +38,9 @@ public class CardInSet {
|
||||
* @param cntCopies
|
||||
* the cnt copies
|
||||
*/
|
||||
public CardInSet(final CardRarity rarity, final int cntCopies, final String picUrl ) {
|
||||
public CardInSet(final CardRarity rarity, final int cntCopies ) {
|
||||
this.rarity = rarity;
|
||||
this.numCopies = cntCopies;
|
||||
this.url = picUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,11 +61,4 @@ public class CardInSet {
|
||||
return this.rarity;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @return
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
package forge.card;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import forge.card.mana.ManaCost;
|
||||
|
||||
/**
|
||||
@@ -34,14 +38,22 @@ public final class CardRules implements ICardCharacteristics {
|
||||
private final ICardFace otherPart;
|
||||
|
||||
private CardAiHints aiHints;
|
||||
private final Map<String, CardInSet> setsPrinted = new TreeMap<String, CardInSet>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
|
||||
|
||||
public CardRules(ICardFace[] faces, CardSplitType altMode, CardAiHints cah) {
|
||||
|
||||
public CardRules(ICardFace[] faces, CardSplitType altMode, CardAiHints cah, Map<String, CardInSet> sets) {
|
||||
splitType = altMode;
|
||||
mainPart = faces[0];
|
||||
otherPart = faces[1];
|
||||
aiHints = cah;
|
||||
setsPrinted.putAll(sets);
|
||||
|
||||
if ( setsPrinted.isEmpty() ) {
|
||||
System.err.println(getName() + " was not assigned any set.");
|
||||
setsPrinted.put(CardEdition.UNKNOWN.getCode(), new CardInSet(CardRarity.Common, 1) );
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTraditional() {
|
||||
@@ -131,8 +143,11 @@ public final class CardRules implements ICardCharacteristics {
|
||||
}
|
||||
|
||||
|
||||
public Iterable<String> getSets() { return mainPart.getSets(); }
|
||||
public CardInSet getEditionInfo(final String setCode) { return mainPart.getEditionInfo(setCode); }
|
||||
public Set<String> getSets() { return this.setsPrinted.keySet(); }
|
||||
public CardInSet getEditionInfo(final String setCode) {
|
||||
final CardInSet result = this.setsPrinted.get(setCode);
|
||||
return result; // if returns null, String.format("Card '%s' was never printed in set '%s'", this.getName(), setCode);
|
||||
}
|
||||
|
||||
|
||||
// vanguard card fields, they don't use sides.
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.card;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -45,6 +46,8 @@ public class CardRulesReader {
|
||||
private CardSplitType altMode = CardSplitType.None;
|
||||
private String handLife = null;
|
||||
|
||||
private Map<String,CardInSet> sets = new TreeMap<String, CardInSet>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
// fields to build CardAiHints
|
||||
private boolean removedFromAIDecks = false;
|
||||
private boolean removedFromRandomDecks = false;
|
||||
@@ -64,6 +67,8 @@ public class CardRulesReader {
|
||||
this.faces[1] = null;
|
||||
this.pictureUrl[0] = null;
|
||||
this.pictureUrl[1] = null;
|
||||
|
||||
this.sets.clear();
|
||||
|
||||
this.handLife = null;
|
||||
this.altMode = CardSplitType.None;
|
||||
@@ -83,7 +88,7 @@ public class CardRulesReader {
|
||||
CardAiHints cah = new CardAiHints(removedFromAIDecks, removedFromRandomDecks, hints, needs );
|
||||
faces[0].assignMissingFields();
|
||||
if ( null != faces[1] ) faces[1].assignMissingFields();
|
||||
final CardRules result = new CardRules(faces, altMode, cah);
|
||||
final CardRules result = new CardRules(faces, altMode, cah, sets);
|
||||
result.setDlUrls(pictureUrl);
|
||||
if ( StringUtils.isNotBlank(handLife))
|
||||
result.setVanguardProperties(handLife);
|
||||
@@ -216,7 +221,8 @@ public class CardRulesReader {
|
||||
} else
|
||||
this.faces[curFace].addSVar(variable, value);
|
||||
} else if ("SetInfo".equals(key)) {
|
||||
CardRulesReader.parseSetInfoLine(value, this.faces[this.curFace].getSetsData());
|
||||
if ( curFace == 0 )
|
||||
CardRulesReader.parseSetInfoLine(value, sets);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -294,7 +300,7 @@ public class CardRulesReader {
|
||||
throw new RuntimeException("Unrecognized rarity string <<" + txtRarity + ">>");
|
||||
}
|
||||
|
||||
final CardInSet cardInSet = new CardInSet(rarity, numIllustrations, pieces.length > 2 ? pieces[2] : null);
|
||||
final CardInSet cardInSet = new CardInSet(rarity, numIllustrations);
|
||||
|
||||
setsData.put(setCode, cardInSet);
|
||||
}
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.card;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* SetInfo class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class EditionInfo {
|
||||
|
||||
/** The Code. */
|
||||
private String code;
|
||||
|
||||
/** The Rarity. */
|
||||
private String rarity;
|
||||
|
||||
/** The URL. */
|
||||
private String url;
|
||||
|
||||
/** The Pic count. */
|
||||
private int picCount;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for SetInfo.
|
||||
* </p>
|
||||
*/
|
||||
public EditionInfo() {
|
||||
this.setCode("");
|
||||
this.setRarity("");
|
||||
this.setUrl("");
|
||||
this.setPicCount(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for SetInfo.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link java.lang.String} object.
|
||||
* @param r
|
||||
* a {@link java.lang.String} object.
|
||||
* @param u
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public EditionInfo(final String c, final String r, final String u) {
|
||||
this.setCode(c);
|
||||
this.setRarity(r);
|
||||
this.setUrl(u);
|
||||
this.setPicCount(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for SetInfo.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link java.lang.String} object.
|
||||
* @param r
|
||||
* a {@link java.lang.String} object.
|
||||
* @param u
|
||||
* a {@link java.lang.String} object.
|
||||
* @param p
|
||||
* a int.
|
||||
*/
|
||||
public EditionInfo(final String c, final String r, final String u, final int p) {
|
||||
this.setCode(c);
|
||||
this.setRarity(r);
|
||||
this.setUrl(u);
|
||||
this.setPicCount(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* toString.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
return this.getCode();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final boolean equals(final Object o) {
|
||||
if (o instanceof EditionInfo) {
|
||||
final EditionInfo siO = (EditionInfo) o;
|
||||
return this.getCode().equals(siO.getCode());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (41 * (41 + this.getCode().hashCode()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the code.
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the code.
|
||||
*
|
||||
* @param code0
|
||||
* the code to set
|
||||
*/
|
||||
public void setCode(final String code0) {
|
||||
this.code = code0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rarity.
|
||||
*
|
||||
* @return the rarity
|
||||
*/
|
||||
public String getRarity() {
|
||||
return this.rarity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rarity.
|
||||
*
|
||||
* @param rarity0
|
||||
* the rarity to set
|
||||
*/
|
||||
public void setRarity(final String rarity0) {
|
||||
this.rarity = rarity0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the url.
|
||||
*
|
||||
* @return the url
|
||||
*/
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the url.
|
||||
*
|
||||
* @param url0
|
||||
* the url to set
|
||||
*/
|
||||
public void setUrl(final String url0) {
|
||||
this.url = url0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pic count.
|
||||
*
|
||||
* @return the picCount
|
||||
*/
|
||||
public int getPicCount() {
|
||||
return this.picCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pic count.
|
||||
*
|
||||
* @param picCount0
|
||||
* the picCount to set
|
||||
*/
|
||||
public void setPicCount(final int picCount0) {
|
||||
this.picCount = picCount0;
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,4 @@ public interface ICardCharacteristics {
|
||||
public abstract int getInitialLoyalty();
|
||||
|
||||
public abstract String getOracleText();
|
||||
|
||||
public abstract Iterable<String> getSets();
|
||||
public abstract CardInSet getEditionInfo(final String setCode);
|
||||
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import javax.swing.filechooser.FileFilter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.gui.download.GuiDownloadSetPicturesLQ;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.util.FileSection;
|
||||
import forge.util.FileSectionManual;
|
||||
@@ -149,7 +150,8 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
||||
for (final Entry<CardPrinted, Integer> card : d.getMain()) {
|
||||
// System.out.println(card.getSets().get(card.getSets().size() - 1).URL);
|
||||
for( int i = card.getValue().intValue(); i > 0; --i ) {
|
||||
list.add(card.getKey().getRules().getEditionInfo(card.getKey().getEdition()).getUrl());
|
||||
String url = GuiDownloadSetPicturesLQ.getCardPictureUrl(card.getKey(), card.getKey().getName());
|
||||
list.add(url);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -450,7 +452,7 @@ public final class GameActionUtil {
|
||||
if (part instanceof CostPayLife) {
|
||||
String amountString = part.getAmount();
|
||||
|
||||
final int amount = amountString.matches("[0-9][0-9]?") ? Integer.parseInt(amountString)
|
||||
final int amount = StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString)
|
||||
: AbilityUtils.calculateAmount(source, amountString, sourceAbility);
|
||||
if (p.canPayLife(amount) && GuiDialog.confirm(source, "Do you want to pay " + amount + " life?" + orString)) {
|
||||
p.payLife(amount, null);
|
||||
@@ -463,7 +465,7 @@ public final class GameActionUtil {
|
||||
|
||||
else if (part instanceof CostDamage) {
|
||||
String amountString = part.getAmount();
|
||||
final int amount = amountString.matches("[0-9][0-9]?") ? Integer.parseInt(amountString)
|
||||
final int amount = StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString)
|
||||
: CardFactoryUtil.xCount(source, source.getSVar(amountString));
|
||||
if (p.canPayLife(amount) && GuiDialog.confirm(source, "Do you want " + source + " to deal " + amount + " damage to you?")) {
|
||||
p.addDamage(amount, source);
|
||||
@@ -477,7 +479,7 @@ public final class GameActionUtil {
|
||||
else if (part instanceof CostPutCounter) {
|
||||
String amountString = part.getAmount();
|
||||
CounterType counterType = ((CostPutCounter) part).getCounter();
|
||||
int amount = amountString.matches("[0-9][0-9]?") ? Integer.parseInt(amountString)
|
||||
int amount = StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString)
|
||||
: CardFactoryUtil.xCount(source, source.getSVar(amountString));
|
||||
String plural = amount > 1 ? "s" : "";
|
||||
if (GuiDialog.confirm(source, "Do you want to put " + amount + " " + counterType.getName()
|
||||
@@ -500,7 +502,7 @@ public final class GameActionUtil {
|
||||
else if (part instanceof CostRemoveCounter) {
|
||||
String amountString = part.getAmount();
|
||||
CounterType counterType = ((CostRemoveCounter) part).getCounter();
|
||||
int amount = amountString.matches("[0-9][0-9]?") ? Integer.parseInt(amountString)
|
||||
int amount = StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString)
|
||||
: CardFactoryUtil.xCount(source, source.getSVar(amountString));
|
||||
String plural = amount > 1 ? "s" : "";
|
||||
if (part.canPay(sourceAbility, source, p, cost, game)
|
||||
|
||||
@@ -60,23 +60,34 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
|
||||
* the card name
|
||||
*/
|
||||
protected final void addCardToList(final ArrayList<DownloadObject> cList, final CardPrinted c, final String cardName) {
|
||||
final String setCode3 = c.getEdition();
|
||||
final CardEdition thisSet = Singletons.getModel().getEditions().get(setCode3);
|
||||
final String setCode2 = thisSet.getCode2();
|
||||
final int artsCnt = c.getRules().getEditionInfo(setCode3).getCopiesCount();
|
||||
|
||||
final String imgFN = CardUtil.buildFilename(c, cardName);
|
||||
final boolean foundSetImage = imgFN.contains(setCode3) || imgFN.contains(setCode2);
|
||||
|
||||
if (!foundSetImage) {
|
||||
String url = getCardPictureUrl(c, cardName);
|
||||
|
||||
final String filename = GuiDownloadPicturesLQ.buildIdealFilename(cardName, c.getArtIndex(), artsCnt);
|
||||
cList.add(new DownloadObject(url, new File(this.picturesPath + File.separator + setCode3, filename)));
|
||||
|
||||
System.out.println(String.format("%s [%s - %s]", cardName, setCode3, thisSet.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCardPictureUrl(final CardPrinted c, final String cardName) {
|
||||
final String urlBase = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/fpics/";
|
||||
|
||||
final String setCode3 = c.getEdition();
|
||||
final CardEdition thisSet = Singletons.getModel().getEditions().get(setCode3);
|
||||
final String setCode2 = thisSet.getCode2();
|
||||
|
||||
final String imgFN = CardUtil.buildFilename(c, cardName);
|
||||
final boolean foundSetImage = imgFN.contains(setCode3) || imgFN.contains(setCode2);
|
||||
|
||||
if (!foundSetImage) {
|
||||
final int artsCnt = c.getRules().getEditionInfo(setCode3).getCopiesCount();
|
||||
final String filename = GuiDownloadPicturesLQ.buildIdealFilename(cardName, c.getArtIndex(), artsCnt);
|
||||
String url = urlBase + setCode2 + "/" + Base64Coder.encodeString(filename, true);
|
||||
cList.add(new DownloadObject(url, new File(this.picturesPath + File.separator + setCode3, filename)));
|
||||
|
||||
System.out.println(String.format("%s [%s - %s]", cardName, setCode3, thisSet.getName()));
|
||||
}
|
||||
|
||||
final int artsCnt = c.getRules().getEditionInfo(setCode3).getCopiesCount();
|
||||
final String filename = GuiDownloadPicturesLQ.buildIdealFilename(cardName, c.getArtIndex(), artsCnt);
|
||||
return urlBase + setCode2 + "/" + Base64Coder.encodeString(filename, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user