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