mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
LQ picture loading
This commit is contained in:
@@ -32,6 +32,7 @@ public class CardRuleCharacteristics {
|
||||
private String ptLine = null;
|
||||
private String[] cardRules = null;
|
||||
private Map<String, CardInSet> setsData = new TreeMap<String, CardInSet>();
|
||||
private String dlUrl;
|
||||
|
||||
/**
|
||||
* Gets the card name.
|
||||
@@ -166,4 +167,12 @@ public class CardRuleCharacteristics {
|
||||
public final void setSetsData(final Map<String, CardInSet> setsData0) {
|
||||
this.setsData = setsData0;
|
||||
}
|
||||
|
||||
public String getDlUrl() {
|
||||
return dlUrl;
|
||||
}
|
||||
|
||||
public void setDlUrl(String dlUrl) {
|
||||
this.dlUrl = dlUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,8 +236,8 @@ public final class CardRules {
|
||||
* @param removedFromAIDecks
|
||||
* the removed from ai decks
|
||||
*/
|
||||
public CardRules(final CardRuleCharacteristics chars, List<String> forgeScript, final boolean isDoubleFacedCard, final CardRules otherPart,
|
||||
final boolean removedFromRandomDecks, final boolean removedFromAIDecks) {
|
||||
public CardRules(final CardRuleCharacteristics chars, List<String> forgeScript, final boolean isDoubleFacedCard,
|
||||
final CardRules otherPart, final boolean removedFromRandomDecks, final boolean removedFromAIDecks) {
|
||||
this.characteristics = chars;
|
||||
this.slavePart = otherPart;
|
||||
this.hasOtherFace = isDoubleFacedCard;
|
||||
@@ -907,4 +907,12 @@ public final class CardRules {
|
||||
public Iterable<String> getCardScript() {
|
||||
return originalScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @return
|
||||
*/
|
||||
public String getPictureUrl() {
|
||||
return characteristics.getDlUrl();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,16 +147,13 @@ public class CardRulesReader {
|
||||
|
||||
case 'S':
|
||||
if (line.startsWith("SVar:RemAIDeck:")) {
|
||||
this.removedFromAIDecks = "True"
|
||||
.equalsIgnoreCase(CardRulesReader.getValueAfterKey(line, "SVar:RemAIDeck:"));
|
||||
|
||||
this.removedFromAIDecks = "True".equalsIgnoreCase(CardRulesReader.getValueAfterKey(line, "SVar:RemAIDeck:"));
|
||||
} else if (line.startsWith("SVar:RemRandomDeck:")) {
|
||||
this.removedFromRandomDecks = "True".equalsIgnoreCase(CardRulesReader.getValueAfterKey(line,
|
||||
"SVar:RemRandomDeck:"));
|
||||
|
||||
this.removedFromRandomDecks = "True".equalsIgnoreCase(CardRulesReader.getValueAfterKey(line, "SVar:RemRandomDeck:"));
|
||||
} else if (line.startsWith("SVar:Picture:")) {
|
||||
this.characteristics[this.curCharacteristics].setDlUrl(CardRulesReader.getValueAfterKey(line, "SVar:Picture:"));
|
||||
} else if (line.startsWith("SetInfo:")) {
|
||||
CardRulesReader.parseSetInfoLine(line, this.characteristics[this.curCharacteristics].getSetsData());
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -19,13 +19,9 @@ package forge.gui.download;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardCharactersticName;
|
||||
import forge.card.CardCharacteristics;
|
||||
import forge.card.CardRules;
|
||||
import forge.gui.GuiDisplayUtil;
|
||||
import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
@@ -43,17 +39,12 @@ import forge.properties.NewConstants;
|
||||
public class GuiDownloadPicturesLQ extends GuiDownloader {
|
||||
|
||||
private static final long serialVersionUID = -2839597792999139007L;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for GuiDownloadQuestImages.
|
||||
* </p>
|
||||
*
|
||||
* @param frame
|
||||
* a array of {@link javax.swing.JFrame} objects.
|
||||
*/
|
||||
private String baseFolder;
|
||||
private ArrayList<DownloadObject> downloads;
|
||||
|
||||
public GuiDownloadPicturesLQ(final JFrame frame) {
|
||||
super(frame);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,54 +56,55 @@ public class GuiDownloadPicturesLQ extends GuiDownloader {
|
||||
*/
|
||||
@Override
|
||||
protected final DownloadObject[] getNeededImages() {
|
||||
// read token names and urls
|
||||
final ArrayList<DownloadObject> cList = new ArrayList<DownloadObject>();
|
||||
|
||||
final String base = ForgeProps.getFile(NewConstants.IMAGE_BASE).getPath();
|
||||
for (final CardPrinted c : CardDb.instance().getAllCards()) {
|
||||
cList.addAll(this.createDLObjects(c, base));
|
||||
// This is called as a virtual method from constructor.
|
||||
baseFolder = ForgeProps.getFile(NewConstants.IMAGE_BASE).getPath();
|
||||
downloads = new ArrayList<DownloadObject>();
|
||||
|
||||
// It is already needed here as initialized variable - that was the best place to initialize
|
||||
|
||||
for (final CardPrinted c : CardDb.instance().getAllUniqueCards()) {
|
||||
System.out.println(c.getName());
|
||||
CardRules firstSide = c.getCard();
|
||||
this.createDLObjects(firstSide);
|
||||
|
||||
CardRules secondSide = firstSide.getSlavePart();
|
||||
if( secondSide != null )
|
||||
this.createDLObjects(secondSide);
|
||||
}
|
||||
|
||||
final ArrayList<DownloadObject> list = new ArrayList<DownloadObject>();
|
||||
|
||||
for (final DownloadObject element : cList) {
|
||||
if (!element.getDestination().exists()) {
|
||||
list.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
// add missing tokens to the list of things to download
|
||||
for (final DownloadObject element : GuiDownloader.readFileWithNames(NewConstants.TOKEN_IMAGES,
|
||||
ForgeProps.getFile(NewConstants.IMAGE_TOKEN))) {
|
||||
if (!element.getDestination().exists()) {
|
||||
list.add(element);
|
||||
downloads.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
// return all card names and urls that are needed
|
||||
return list.toArray(new DownloadObject[list.size()]);
|
||||
return downloads.toArray(new DownloadObject[downloads.size()]);
|
||||
} // getNeededImages()
|
||||
|
||||
private List<DownloadObject> createDLObjects(final CardPrinted c, final String base) {
|
||||
final ArrayList<DownloadObject> ret = new ArrayList<DownloadObject>();
|
||||
private void createDLObjects(final CardRules c) {
|
||||
|
||||
Card fc = c.toForgeCard();
|
||||
for (final CardCharactersticName state : fc.getStates()) {
|
||||
CardCharacteristics stateCharacteristics = fc.getState(state);
|
||||
final String url = stateCharacteristics.getSVar("Picture");
|
||||
if (!url.isEmpty()) {
|
||||
final String[] urls = url.split("\\\\");
|
||||
final String url = c.getPictureUrl();
|
||||
if (url != null && !url.isEmpty()) {
|
||||
final String[] urls = url.split("\\\\");
|
||||
|
||||
final String iName = GuiDisplayUtil.cleanString(stateCharacteristics.getImageName());
|
||||
ret.add(new DownloadObject(urls[0], new File(base, iName + ".jpg")));
|
||||
|
||||
for (int j = 1; j < urls.length; j++) {
|
||||
ret.add(new DownloadObject(urls[j], new File(base, iName + j + ".jpg")));
|
||||
}
|
||||
final String sName = GuiDisplayUtil.cleanString(c.getName());
|
||||
addDownloadObject(urls[0], new File(baseFolder, sName + ".jpg"));
|
||||
|
||||
for (int j = 1; j < urls.length; j++) {
|
||||
addDownloadObject(urls[j], new File(baseFolder, sName + j + ".jpg"));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void addDownloadObject(String url, File destFile) {
|
||||
if (!destFile.exists()) {
|
||||
downloads.add(new DownloadObject(url, destFile));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user