mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Merge pull request #2867 from kevlahnota/newmaster2
add imagefetcher for Planechase BG
This commit is contained in:
@@ -10,7 +10,9 @@ import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
||||
|
||||
import forge.Forge;
|
||||
import forge.Graphics;
|
||||
import forge.gui.GuiBase;
|
||||
import forge.localinstance.properties.ForgeConstants;
|
||||
import forge.util.ImageFetcher;
|
||||
|
||||
public enum FSkinTexture implements FImage {
|
||||
BG_TEXTURE(ForgeConstants.TEXTURE_BG_FILE, true, false),
|
||||
@@ -198,7 +200,7 @@ public enum FSkinTexture implements FImage {
|
||||
private final boolean repeat;
|
||||
private Texture texture;
|
||||
private final boolean isPlanechaseBG;
|
||||
private static List<String> PlanesValue;
|
||||
private static List<String> planechaseString;
|
||||
private boolean isloaded = false;
|
||||
private boolean hasError = false;
|
||||
|
||||
@@ -207,19 +209,18 @@ public enum FSkinTexture implements FImage {
|
||||
repeat = repeat0;
|
||||
isPlanechaseBG = isPlanechaseBG0;
|
||||
}
|
||||
|
||||
static {
|
||||
PlanesValue = new ArrayList<>();
|
||||
for (FSkinTexture PlanesEnum : FSkinTexture.values()) {
|
||||
PlanesValue.add(PlanesEnum.filename
|
||||
.replace(".jpg", "")
|
||||
.replace("'", "")
|
||||
.replace("-", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getValues() {
|
||||
return Collections.unmodifiableList(PlanesValue);
|
||||
if (planechaseString == null) {
|
||||
planechaseString = new ArrayList<>();
|
||||
for (FSkinTexture fskinTexture : FSkinTexture.values()) {
|
||||
if (fskinTexture.isPlanechaseBG)
|
||||
planechaseString.add(fskinTexture.filename
|
||||
.replace(".jpg", "")
|
||||
.replace("'", "")
|
||||
.replace("-", ""));
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(planechaseString);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
@@ -243,6 +244,11 @@ public enum FSkinTexture implements FImage {
|
||||
//use default file if can't use preferred file
|
||||
FileHandle defaultFile = FSkin.getDefaultSkinFile(filename);
|
||||
if(isPlanechaseBG) {
|
||||
ImageFetcher fetcher = GuiBase.getInterface().getImageFetcher();
|
||||
fetcher.fetchImage("PLANECHASEBG:" + filename, () -> {
|
||||
hasError = false;
|
||||
load();
|
||||
});
|
||||
defaultFile = FSkin.getSkinFile(ForgeConstants.MATCH_BG_FILE);
|
||||
if(!defaultFile.exists())
|
||||
defaultFile = FSkin.getDefaultSkinFile(ForgeConstants.MATCH_BG_FILE);
|
||||
|
||||
@@ -75,22 +75,32 @@ public class LibGDXImageFetcher extends ImageFetcher {
|
||||
|
||||
public void run() {
|
||||
for (String urlToDownload : downloadUrls) {
|
||||
boolean isPlanechaseBG = urlToDownload.startsWith("https://downloads.cardforge.org/images/planes/");
|
||||
try {
|
||||
doFetch(tofullBorder(urlToDownload));
|
||||
break;
|
||||
if (isPlanechaseBG) {
|
||||
doFetch(urlToDownload);
|
||||
break;
|
||||
} else {
|
||||
doFetch(tofullBorder(urlToDownload));
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("Failed to download card [" + destPath + "] image: " + e.getMessage());
|
||||
if (urlToDownload.contains("tokens")) {
|
||||
int setIndex = urlToDownload.lastIndexOf('_');
|
||||
int typeIndex = urlToDownload.lastIndexOf('.');
|
||||
String setlessFilename = urlToDownload.substring(0, setIndex);
|
||||
String extension = urlToDownload.substring(typeIndex);
|
||||
urlToDownload = setlessFilename+extension;
|
||||
try {
|
||||
doFetch(tofullBorder(urlToDownload));
|
||||
break;
|
||||
} catch (IOException t) {
|
||||
System.out.println("Failed to download setless token [" + destPath + "]: " + e.getMessage());
|
||||
if (isPlanechaseBG) {
|
||||
System.out.println("Failed to download planechase background [" + destPath + "] image: " + e.getMessage());
|
||||
} else {
|
||||
System.out.println("Failed to download card [" + destPath + "] image: " + e.getMessage());
|
||||
if (urlToDownload.contains("tokens")) {
|
||||
int setIndex = urlToDownload.lastIndexOf('_');
|
||||
int typeIndex = urlToDownload.lastIndexOf('.');
|
||||
String setlessFilename = urlToDownload.substring(0, setIndex);
|
||||
String extension = urlToDownload.substring(typeIndex);
|
||||
urlToDownload = setlessFilename + extension;
|
||||
try {
|
||||
doFetch(tofullBorder(urlToDownload));
|
||||
break;
|
||||
} catch (IOException t) {
|
||||
System.out.println("Failed to download setless token [" + destPath + "]: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,20 @@ public abstract class ImageFetcher {
|
||||
if (imageKey.length() < 2)
|
||||
return;
|
||||
|
||||
//planechaseBG file...
|
||||
if (imageKey.startsWith("PLANECHASEBG:")) {
|
||||
final ArrayList<String> downloadUrls = new ArrayList<>();
|
||||
final String filename = imageKey.substring("PLANECHASEBG:".length());
|
||||
downloadUrls.add("https://downloads.cardforge.org/images/planes/" + filename);
|
||||
FileUtil.ensureDirectoryExists(ForgeConstants.CACHE_PLANECHASE_PICS_DIR);
|
||||
File destFile = new File(ForgeConstants.CACHE_PLANECHASE_PICS_DIR, filename);
|
||||
if (destFile.exists())
|
||||
return;
|
||||
|
||||
setupObserver(destFile.getAbsolutePath(), callback, downloadUrls);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean useArtCrop = "Crop".equals(FModel.getPreferences().getPref(ForgePreferences.FPref.UI_CARD_ART_FORMAT));
|
||||
final String prefix = imageKey.substring(0, 2);
|
||||
final ArrayList<String> downloadUrls = new ArrayList<>();
|
||||
@@ -234,8 +248,9 @@ public abstract class ImageFetcher {
|
||||
return;
|
||||
}
|
||||
|
||||
final String destPath = destFile.getAbsolutePath();
|
||||
|
||||
setupObserver(destFile.getAbsolutePath(), callback, downloadUrls);
|
||||
}
|
||||
private void setupObserver(final String destPath, final Callback callback, final ArrayList<String> downloadUrls) {
|
||||
// Note: No synchronization is needed here because this is executed on
|
||||
// EDT thread (see assert on top) and so is the notification of observers.
|
||||
HashSet<Callback> observers = currentFetches.get(destPath);
|
||||
|
||||
Reference in New Issue
Block a user