mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
dedicated method to get download url for card pictures
This commit is contained in:
@@ -171,8 +171,9 @@ public class ImageCache {
|
||||
// Inventory items don't have to know how a certain client should draw them.
|
||||
// That's why this method is not encapsulated and overloaded in the InventoryItem descendants
|
||||
public static String getImageKey(InventoryItem ii, boolean altState) {
|
||||
if ( ii instanceof CardPrinted )
|
||||
if ( ii instanceof CardPrinted ) {
|
||||
return getImageKey((CardPrinted)ii, altState, true);
|
||||
}
|
||||
if ( ii instanceof TournamentPack )
|
||||
return ImageCache.TOURNAMENTPACK_PREFIX + ((TournamentPack)ii).getEdition();
|
||||
if ( ii instanceof BoosterPack )
|
||||
@@ -186,7 +187,11 @@ public class ImageCache {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getImageLocator(CardPrinted cp, String nameToUse, boolean includeSet, boolean isDownloadUrl) {
|
||||
private static String getImageLocator(CardPrinted cp, boolean backFace, boolean includeSet, boolean isDownloadUrl) {
|
||||
final String nameToUse = getNameToUse(cp, backFace);
|
||||
if ( null == nameToUse )
|
||||
return null;
|
||||
|
||||
StringBuilder s = new StringBuilder();
|
||||
|
||||
CardRules card = cp.getRules();
|
||||
@@ -197,18 +202,22 @@ public class ImageCache {
|
||||
if (includeSet) {
|
||||
cntPictures = card.getEditionInfo(edition).getCopiesCount();
|
||||
} else {
|
||||
// raise the art index limit to the maximum of the sets this card was printed in
|
||||
int maxCntPictures = 1;
|
||||
for (String set : card.getSets()) {
|
||||
maxCntPictures = Math.max(maxCntPictures, card.getEditionInfo(set).getCopiesCount());
|
||||
}
|
||||
cntPictures = maxCntPictures;
|
||||
// without set number of pictures equals number of urls provided in Svar:Picture
|
||||
String urls = backFace ? card.getPictureOtherSideUrl() : card.getPictureUrl();
|
||||
cntPictures = StringUtils.countMatches(urls, "\\\\") + 1;
|
||||
|
||||
// // raise the art index limit to the maximum of the sets this card was printed in
|
||||
// int maxCntPictures = 1;
|
||||
// for (String set : card.getSets()) {
|
||||
// maxCntPictures = Math.max(maxCntPictures, card.getEditionInfo(set).getCopiesCount());
|
||||
// }
|
||||
// cntPictures = maxCntPictures;
|
||||
}
|
||||
|
||||
int artIdx = cp.getArtIndex();
|
||||
if (cntPictures > 1 ) {
|
||||
if ( cntPictures <= artIdx )
|
||||
artIdx = Math.min(artIdx, cntPictures - 1);
|
||||
artIdx = cntPictures == 1 ? 0 : artIdx % cntPictures;
|
||||
s.append(artIdx + 1);
|
||||
}
|
||||
|
||||
@@ -239,25 +248,28 @@ public class ImageCache {
|
||||
: NewConstants.CACHE_CARD_PICS_SUBDIR.get(edition); // may use custom paths though
|
||||
}
|
||||
|
||||
public static String getImageName(CardPrinted cp) {
|
||||
return CardSplitType.Split != cp.getRules().getSplitType() ? cp.getName() : cp.getRules().getMainPart().getName() + cp.getRules().getOtherPart().getName();
|
||||
}
|
||||
|
||||
public static String getImageKey(CardPrinted cp, boolean backFace, boolean includeSet) {
|
||||
private static String getNameToUse(CardPrinted cp, boolean backFace) {
|
||||
final CardRules card = cp.getRules();
|
||||
final String nameToUse;
|
||||
if (backFace) {
|
||||
if ( card.getSplitType() == CardSplitType.Transform )
|
||||
nameToUse = card.getOtherPart().getName();
|
||||
return card.getOtherPart().getName();
|
||||
else
|
||||
return null;
|
||||
} else if(CardSplitType.Split == cp.getRules().getSplitType()) {
|
||||
return card.getMainPart().getName() + card.getOtherPart().getName();
|
||||
} else {
|
||||
nameToUse = getImageName(cp);
|
||||
return cp.getName();
|
||||
}
|
||||
}
|
||||
|
||||
return getImageLocator(cp, nameToUse, includeSet, false);
|
||||
public static String getImageKey(CardPrinted cp, boolean backFace, boolean includeSet) {
|
||||
return getImageLocator(cp, backFace, includeSet, false);
|
||||
}
|
||||
|
||||
public static String getDownloadUrl(CardPrinted cp, boolean backFace, boolean includeSet) {
|
||||
return getImageLocator(cp, backFace, includeSet, true);
|
||||
}
|
||||
|
||||
public static String toMWSFilename(String in) {
|
||||
final StringBuffer out = new StringBuffer();
|
||||
char c;
|
||||
|
||||
@@ -140,7 +140,7 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
||||
// System.out.println(card.getSets().get(card.getSets().size() - 1).URL);
|
||||
for (int i = card.getValue().intValue(); i > 0; --i ) {
|
||||
CardPrinted r = card.getKey();
|
||||
String url = NewConstants.URL_PIC_DOWNLOAD + ImageCache.getImageLocator(r, ImageCache.getImageName(r), true, true);
|
||||
String url = NewConstants.URL_PIC_DOWNLOAD + ImageCache.getDownloadUrl(r, false, true);
|
||||
list.add(url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,11 +48,11 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
|
||||
// we don't want cards from unknown sets
|
||||
continue;
|
||||
}
|
||||
String url = ImageCache.getImageLocator(c, ImageCache.getImageName(c), true, true);
|
||||
String url = ImageCache.getDownloadUrl(c, false, true);
|
||||
addDLObject(url, ImageCache.getImageKey(c), downloads);
|
||||
|
||||
if ( c.getRules().getSplitType() == CardSplitType.Transform ) {
|
||||
String url2 = ImageCache.getImageLocator(c, c.getRules().getOtherPart().getName(), true, true);
|
||||
String url2 = ImageCache.getDownloadUrl(c, true, true);
|
||||
addDLObject(url2, ImageCache.getImageKey(c, true), downloads);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user