mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Merge remote-tracking branch 'upstream/master' into collector-number-in-card-list-and-card-db-refactoring
This commit is contained in:
@@ -224,7 +224,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
}
|
||||
|
||||
artIds.put(key, artIdx);
|
||||
addCard(new PaperCard(cr, e.getCode(), cis.rarity, artIdx, cis.collectorNumber));
|
||||
addCard(new PaperCard(cr, e.getCode(), cis.rarity, artIdx, false, cis.collectorNumber, cis.artistName));
|
||||
}
|
||||
|
||||
public void loadCard(String cardName, CardRules cr) {
|
||||
@@ -236,6 +236,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
for (CardInSet cis : cardsInSet)
|
||||
addSetCard(e, cis, cr);
|
||||
}
|
||||
|
||||
reIndex();
|
||||
}
|
||||
|
||||
@@ -289,10 +290,10 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
for (CardRules cr : rulesByName.values()) {
|
||||
if (!contains(cr.getName())) {
|
||||
if (upcomingSet != null) {
|
||||
addCard(new PaperCard(cr, upcomingSet.getCode(), CardRarity.Unknown));
|
||||
addCard(new PaperCard(cr, upcomingSet.getCode(), CardRarity.Unknown, IPaperCard.DEFAULT_ART_INDEX));
|
||||
} else if (enableUnknownCards && !this.filtered.contains(cr.getName())) {
|
||||
System.err.println("The card " + cr.getName() + " was not assigned to any set. Adding it to UNKNOWN set... to fix see res/editions/ folder. ");
|
||||
addCard(new PaperCard(cr, CardEdition.UNKNOWN.getCode(), CardRarity.Special));
|
||||
addCard(new PaperCard(cr, CardEdition.UNKNOWN.getCode(), CardRarity.Special, IPaperCard.DEFAULT_ART_INDEX));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -958,7 +959,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
System.err.println("We're sorry, but this card is not supported yet.");
|
||||
}
|
||||
|
||||
return new PaperCard(CardRules.getUnsupportedCardNamed(request.cardName), cardEdition.getCode(), cardRarity);
|
||||
return new PaperCard(CardRules.getUnsupportedCardNamed(request.cardName), cardEdition.getCode(), cardRarity, IPaperCard.DEFAULT_ART_INDEX);
|
||||
|
||||
}
|
||||
|
||||
@@ -1016,7 +1017,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
}
|
||||
}
|
||||
if (paperCards.isEmpty()) {
|
||||
paperCards.add(new PaperCard(rules, CardEdition.UNKNOWN.getCode(), CardRarity.Special));
|
||||
paperCards.add(new PaperCard(rules, CardEdition.UNKNOWN.getCode(), CardRarity.Special, IPaperCard.DEFAULT_ART_INDEX));
|
||||
}
|
||||
// 2. add them to db
|
||||
for (PaperCard paperCard : paperCards) {
|
||||
|
||||
@@ -163,11 +163,13 @@ public final class CardEdition implements Comparable<CardEdition> {
|
||||
public final CardRarity rarity;
|
||||
public final String collectorNumber;
|
||||
public final String name;
|
||||
public final String artistName;
|
||||
|
||||
public CardInSet(final String name, final String collectorNumber, final CardRarity rarity) {
|
||||
public CardInSet(final String name, final String collectorNumber, final CardRarity rarity, final String artistName) {
|
||||
this.name = name;
|
||||
this.collectorNumber = collectorNumber;
|
||||
this.rarity = rarity;
|
||||
this.artistName = artistName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
@@ -181,6 +183,10 @@ public final class CardEdition implements Comparable<CardEdition> {
|
||||
sb.append(' ');
|
||||
}
|
||||
sb.append(name);
|
||||
if (artistName != null) {
|
||||
sb.append(" @");
|
||||
sb.append(artistName);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -535,7 +541,7 @@ public final class CardEdition implements Comparable<CardEdition> {
|
||||
* name - grouping #5
|
||||
*/
|
||||
// "(^(.?[0-9A-Z]+.?))?(([SCURML]) )?(.*)$"
|
||||
"(^(.?[0-9A-Z]+\\S?[A-Z]*)\\s)?(([SCURML])\\s)?(.*)$"
|
||||
"(^(.?[0-9A-Z]+\\S?[A-Z]*)\\s)?(([SCURML])\\s)?([^@]*)( @(.*))?$"
|
||||
);
|
||||
|
||||
ListMultimap<String, CardInSet> cardMap = ArrayListMultimap.create();
|
||||
@@ -560,7 +566,8 @@ public final class CardEdition implements Comparable<CardEdition> {
|
||||
String collectorNumber = matcher.group(2);
|
||||
CardRarity r = CardRarity.smartValueOf(matcher.group(4));
|
||||
String cardName = matcher.group(5);
|
||||
CardInSet cis = new CardInSet(cardName, collectorNumber, r);
|
||||
String artistName = matcher.group(7);
|
||||
CardInSet cis = new CardInSet(cardName, collectorNumber, r, artistName);
|
||||
|
||||
cardMap.put(sectionName, cis);
|
||||
}
|
||||
|
||||
@@ -234,6 +234,7 @@ public interface IPaperCard extends InventoryItem, Serializable {
|
||||
boolean isToken();
|
||||
CardRules getRules();
|
||||
CardRarity getRarity();
|
||||
String getArtist();
|
||||
|
||||
String getItemType();
|
||||
|
||||
|
||||
@@ -17,7 +17,12 @@
|
||||
*/
|
||||
package forge.item;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.ImageKeys;
|
||||
import forge.StaticData;
|
||||
import forge.card.CardDb;
|
||||
@@ -28,10 +33,6 @@ import forge.util.CardTranslation;
|
||||
import forge.util.Localizer;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A lightweight version of a card that matches real-world cards, to use outside of games (eg. inventory, decks, trade).
|
||||
* <br><br>
|
||||
@@ -53,9 +54,10 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
(see getCollectorNumber())
|
||||
*/
|
||||
private String collectorNumber = null;
|
||||
private final String artist;
|
||||
private final int artIndex;
|
||||
private final boolean foil;
|
||||
private Boolean hasImage = null;
|
||||
private Boolean hasImage;
|
||||
|
||||
// Calculated fields are below:
|
||||
private transient CardRarity rarity; // rarity is given in ctor when set is assigned
|
||||
@@ -114,6 +116,11 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
return rarity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArtist() {
|
||||
return artist;
|
||||
}
|
||||
|
||||
/* FIXME: At the moment, every card can get Foiled, with no restriction on the
|
||||
corresponding Edition - so we could Foil even Alpha cards.
|
||||
*/
|
||||
@@ -123,7 +130,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
|
||||
if (this.foiledVersion == null) {
|
||||
this.foiledVersion = new PaperCard(this.rules, this.edition, this.rarity,
|
||||
this.artIndex, true, String.valueOf(collectorNumber));
|
||||
this.artIndex, true, String.valueOf(collectorNumber), this.artist);
|
||||
}
|
||||
return this.foiledVersion;
|
||||
}
|
||||
@@ -162,16 +169,12 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
}
|
||||
};
|
||||
|
||||
public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0) {
|
||||
this(rules0, edition0, rarity0, IPaperCard.DEFAULT_ART_INDEX, false);
|
||||
}
|
||||
|
||||
public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0, final int artIndex0) {
|
||||
this(rules0, edition0, rarity0, artIndex0, false);
|
||||
this(rules0, edition0, rarity0, artIndex0, false, "");
|
||||
}
|
||||
|
||||
public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0, final int artIndex0,
|
||||
final boolean foil0) {
|
||||
final boolean foil0, final String artist0) {
|
||||
if (rules0 == null || edition0 == null || rarity0 == null) {
|
||||
throw new IllegalArgumentException("Cannot create card without rules, edition or rarity");
|
||||
}
|
||||
@@ -181,16 +184,12 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
artIndex = artIndex0 >= IPaperCard.DEFAULT_ART_INDEX ? artIndex0 : IPaperCard.DEFAULT_ART_INDEX;
|
||||
foil = foil0;
|
||||
rarity = rarity0;
|
||||
}
|
||||
|
||||
public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0, final int artIndex0,
|
||||
final String collectorNumber0) {
|
||||
this(rules0, edition0, rarity0, artIndex0, false, collectorNumber0);
|
||||
artist = (artist0 != null ? artist0 : "");
|
||||
}
|
||||
|
||||
public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0,
|
||||
final int artIndex0, final boolean foil0, final String collectorNumber0) {
|
||||
this(rules0, edition0, rarity0, artIndex0, foil0);
|
||||
final int artIndex0, final boolean foil0, final String collectorNumber0, final String artist) {
|
||||
this(rules0, edition0, rarity0, artIndex0, foil0, artist);
|
||||
if ((collectorNumber0 == null) || (collectorNumber0.length() == 0))
|
||||
collectorNumber = IPaperCard.NO_COLLECTOR_NUMBER;
|
||||
else
|
||||
|
||||
@@ -143,6 +143,7 @@ public class PaperToken implements InventoryItemFromSet, IPaperCard {
|
||||
@Override public CardRules getRules() { return card; }
|
||||
|
||||
@Override public CardRarity getRarity() { return CardRarity.None; }
|
||||
@Override public String getArtist() { /*TODO*/ return ""; }
|
||||
|
||||
// Unfortunately this is a property of token, cannot move it outside of class
|
||||
public String getImageFilename() { return getImageFilename(1); }
|
||||
|
||||
@@ -6,7 +6,6 @@ import forge.card.CardDb;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardSplitType;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.PaperToken;
|
||||
|
||||
public class ImageUtil {
|
||||
public static float getNearestHQSize(float baseSize, float actualSize) {
|
||||
@@ -30,28 +29,6 @@ public class ImageUtil {
|
||||
return cp;
|
||||
}
|
||||
|
||||
public static PaperToken getPaperTokenFromImageKey(String key) {
|
||||
if ( key == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
key = key.substring(2);
|
||||
int index = key.lastIndexOf('_');
|
||||
if (index != -1) {
|
||||
String script = key.substring(0, index);
|
||||
String edition = key.substring(index + 1);
|
||||
if (script.startsWith("emblem"))
|
||||
return null;
|
||||
if (null == StaticData.instance().getCardEdition(edition)) {
|
||||
script = key;
|
||||
edition = "???";
|
||||
}
|
||||
script = script.replaceAll("[0-9]*$", "");
|
||||
return StaticData.instance().getAllTokens().getToken(script, edition);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getImageRelativePath(PaperCard cp, boolean backFace, boolean includeSet, boolean isDownloadUrl) {
|
||||
final String nameToUse = cp == null ? null : getNameToUse(cp, backFace);
|
||||
if (nameToUse == null) {
|
||||
@@ -78,7 +55,7 @@ public class ImageUtil {
|
||||
|
||||
int artIdx = cp.getArtIndex() - 1;
|
||||
if (hasManyPictures) {
|
||||
if ( cntPictures <= artIdx ) // prevent overflow
|
||||
if (cntPictures <= artIdx) // prevent overflow
|
||||
artIdx = cntPictures == 0 ? 0 : artIdx % cntPictures;
|
||||
s.append(artIdx + 1);
|
||||
}
|
||||
@@ -113,8 +90,8 @@ public class ImageUtil {
|
||||
|
||||
public static String getNameToUse(PaperCard cp, boolean backFace) {
|
||||
final CardRules card = cp.getRules();
|
||||
if (backFace ) {
|
||||
if ( hasBackFacePicture(cp) )
|
||||
if (backFace) {
|
||||
if (hasBackFacePicture(cp))
|
||||
if (card.getOtherPart() != null) {
|
||||
return card.getOtherPart().getName();
|
||||
} else if (!card.getMeldWith().isEmpty()) {
|
||||
@@ -140,7 +117,7 @@ public class ImageUtil {
|
||||
return getImageRelativePath(cp, backFace, true, true);
|
||||
}
|
||||
|
||||
public static String getScryfallDownloadUrl(PaperCard cp, boolean backFace, String setCode, String langCode){
|
||||
public static String getScryfallDownloadUrl(PaperCard cp, boolean backFace, String setCode, String langCode, boolean useArtCrop){
|
||||
String editionCode;
|
||||
if ((setCode != null) && (setCode.length() > 0))
|
||||
editionCode = setCode;
|
||||
@@ -149,12 +126,13 @@ public class ImageUtil {
|
||||
String cardCollectorNumber = cp.getCollectorNumber();
|
||||
// Hack to account for variations in Arabian Nights
|
||||
cardCollectorNumber = cardCollectorNumber.replace("+", "†");
|
||||
String versionParam = useArtCrop ? "art_crop" : "normal";
|
||||
String faceParam = "";
|
||||
if (cp.getRules().getOtherPart() != null) {
|
||||
faceParam = (backFace ? "&face=back" : "&face=front");
|
||||
}
|
||||
return String.format("%s/%s/%s?format=image&version=normal%s", editionCode, cardCollectorNumber,
|
||||
langCode, faceParam);
|
||||
return String.format("%s/%s/%s?format=image&version=%s%s", editionCode, cardCollectorNumber,
|
||||
langCode, versionParam, faceParam);
|
||||
}
|
||||
|
||||
public static String toMWSFilename(String in) {
|
||||
|
||||
Reference in New Issue
Block a user