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