mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Forge will no longer crash when there are decks with unsupported cards. These cards will appear in decks and games player starts as a dummy without cost, types, abilities, but with explanation in card's text
This commit is contained in:
@@ -490,4 +490,17 @@ public final class CardRules implements ICardCharacteristics {
|
||||
} // unsuported
|
||||
}
|
||||
}
|
||||
|
||||
public static CardRules getUnsupportedCardNamed(String name) {
|
||||
CardAiHints cah = new CardAiHints(true, true, null, null);
|
||||
CardFace[] faces = { new CardFace(name), null};
|
||||
faces[0].setColor(ColorSet.fromMask(0));
|
||||
faces[0].setType(CardType.parse(""));
|
||||
faces[0].setOracleText("This card is not supported by Forge. Whenever you start a game with this card, it will be bugged.");
|
||||
faces[0].setNonAbilityText("This card is not supported by Forge.\nWhenever you start a game with this card, it will be bugged.");
|
||||
faces[0].assignMissingFields();
|
||||
final CardRules result = new CardRules(faces, CardSplitType.None, cah);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,14 +64,16 @@ public class CardPool extends ItemPool<PaperCard> {
|
||||
cp = StaticData.instance().getVariantCards().getCard(cardName, setCode);
|
||||
}
|
||||
|
||||
if (cp == null )
|
||||
throw new RuntimeException(String.format("Card %s from %s is not supported by Forge, as it's neither a known common card nor one of casual variants' card.", cardName, setCode ));
|
||||
|
||||
boolean artIndexExplicitlySet = artIndex > 0 || Character.isDigit(cardName.charAt(cardName.length()-1)) && cardName.charAt(cardName.length()-2) == CardDb.NameSetSeparator;
|
||||
setCode = cp.getEdition();
|
||||
cardName = cp.getName();
|
||||
|
||||
int artCount = isCommonCard ? StaticData.instance().getCommonCards().getArtCount(cardName, setCode) : 1;
|
||||
boolean artIndexExplicitlySet = artIndex > 0 || Character.isDigit(cardName.charAt(cardName.length()-1)) && cardName.charAt(cardName.length()-2) == CardDb.NameSetSeparator;
|
||||
int artCount = 1;
|
||||
|
||||
if (cp != null ) {
|
||||
setCode = cp.getEdition();
|
||||
cardName = cp.getName();
|
||||
artCount = isCommonCard ? StaticData.instance().getCommonCards().getArtCount(cardName, setCode) : 1;
|
||||
}
|
||||
else
|
||||
cp = PaperCard.createUnsuportedCard(cardName);
|
||||
|
||||
if (artIndexExplicitlySet || artCount <= 1) {
|
||||
// either a specific art index is specified, or there is only one art, so just add the card
|
||||
|
||||
@@ -249,6 +249,8 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
||||
if( c == null)
|
||||
c = StaticData.instance().getCommonCards().getCardFromEdition(cardName, dayAfterNewestSetRelease, SetPreference.Latest, -1);
|
||||
// this is to randomize art of all those cards
|
||||
if( c == null ) // I give up!
|
||||
c = cp.getKey();
|
||||
newPool.add(cardName, c.getEdition(), cp.getValue());
|
||||
} else
|
||||
newPool.add(c, cp.getValue());
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.item;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.CardRules;
|
||||
|
||||
@@ -190,4 +191,8 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
|
||||
return Integer.compare(artIndex, o.getArtIndex());
|
||||
}
|
||||
|
||||
public static PaperCard createUnsuportedCard(String cardName) {
|
||||
return new PaperCard(CardRules.getUnsupportedCardNamed(cardName), CardEdition.UNKNOWN.getCode(), CardRarity.Unknown, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +144,9 @@ public class ImageCache {
|
||||
if (imageKey.startsWith(ImageKeys.CARD_PREFIX))
|
||||
imageKey = getImageKey(getPaperCardFromImageKey(imageKey.substring(2)), altState, true);
|
||||
|
||||
if (StringUtils.isBlank(imageKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Load from file and add to cache if not found in cache initially.
|
||||
BufferedImage original = getImage(imageKey);
|
||||
@@ -153,7 +156,7 @@ public class ImageCache {
|
||||
if (original == null) {
|
||||
if (useDefaultIfNotFound) {
|
||||
original = _defaultImage;
|
||||
_CACHE.put(imageKey, _defaultImage);
|
||||
_CACHE.put(imageKey, _defaultImage);
|
||||
} else {
|
||||
original = null;
|
||||
}
|
||||
@@ -243,7 +246,7 @@ public class ImageCache {
|
||||
|
||||
|
||||
private static String getImageRelativePath(PaperCard cp, boolean backFace, boolean includeSet, boolean isDownloadUrl) {
|
||||
final String nameToUse = getNameToUse(cp, backFace);
|
||||
final String nameToUse = cp == null ? null : getNameToUse(cp, backFace);
|
||||
if ( null == nameToUse )
|
||||
return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user