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