mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Add ability to generate proxies from deck editor
This commit is contained in:
19
pom.xml
19
pom.xml
@@ -198,7 +198,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.google.code.maven-replacer-plugin</groupId>
|
<groupId>com.google.code.maven-replacer-plugin</groupId>
|
||||||
<artifactId>maven-replacer-plugin</artifactId>
|
<artifactId>maven-replacer-plugin</artifactId>
|
||||||
<version>1.3.8</version>
|
<version>1.3.9</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -275,7 +275,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven.wagon</groupId>
|
<groupId>org.apache.maven.wagon</groupId>
|
||||||
<artifactId>wagon-ftp</artifactId>
|
<artifactId>wagon-ftp</artifactId>
|
||||||
<version>1.0</version>
|
<version>2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
@@ -291,7 +291,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven.wagon</groupId>
|
<groupId>org.apache.maven.wagon</groupId>
|
||||||
<artifactId>wagon-ftp</artifactId>
|
<artifactId>wagon-ftp</artifactId>
|
||||||
<version>1.0</version>
|
<version>2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
@@ -535,17 +535,17 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>r09</version>
|
<version>10.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.thoughtworks.xstream</groupId>
|
<groupId>com.thoughtworks.xstream</groupId>
|
||||||
<artifactId>xstream</artifactId>
|
<artifactId>xstream</artifactId>
|
||||||
<version>1.3.1</version>
|
<version>1.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.testng</groupId>
|
<groupId>org.testng</groupId>
|
||||||
<artifactId>testng</artifactId>
|
<artifactId>testng</artifactId>
|
||||||
<version>6.1.1</version>
|
<version>6.2.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -621,7 +621,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.mail</groupId>
|
<groupId>javax.mail</groupId>
|
||||||
<artifactId>mail</artifactId>
|
<artifactId>mail</artifactId>
|
||||||
<version>1.4.1</version>
|
<version>1.4.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.freemarker</groupId>
|
||||||
|
<artifactId>freemarker</artifactId>
|
||||||
|
<version>2.3.18</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,37 @@
|
|||||||
package forge.deck;
|
package forge.deck;
|
||||||
|
|
||||||
|
import static java.lang.Integer.parseInt;
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import freemarker.template.TemplateException;
|
||||||
|
import freemarker.template.Template;
|
||||||
|
import freemarker.template.Configuration;
|
||||||
|
import freemarker.template.DefaultObjectWrapper;
|
||||||
|
|
||||||
|
import forge.Card;
|
||||||
import forge.FileUtil;
|
import forge.FileUtil;
|
||||||
import forge.PlayerType;
|
import forge.PlayerType;
|
||||||
import forge.error.ErrorViewer;
|
import forge.error.ErrorViewer;
|
||||||
@@ -11,46 +42,36 @@ import forge.item.ItemPoolView;
|
|||||||
import forge.properties.ForgeProps;
|
import forge.properties.ForgeProps;
|
||||||
import forge.properties.NewConstants;
|
import forge.properties.NewConstants;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.filechooser.FileFilter;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import static java.lang.Integer.parseInt;
|
|
||||||
import static java.lang.String.format;
|
|
||||||
|
|
||||||
|
|
||||||
//reads and writeDeck Deck objects
|
//reads and writeDeck Deck objects
|
||||||
/**
|
/**
|
||||||
* <p>DeckManager class.</p>
|
* <p>
|
||||||
|
* DeckManager class.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class DeckManager {
|
public class DeckManager {
|
||||||
/** Constant <code>BDKFileFilter</code> */
|
/** Constant <code>BDKFileFilter</code>. */
|
||||||
private static FilenameFilter BDKFileFilter = new FilenameFilter() {
|
private static FilenameFilter bdkFileFilter = new FilenameFilter() {
|
||||||
public boolean accept(File dir, String name) {
|
public boolean accept(final File dir, final String name) {
|
||||||
return name.endsWith(".bdk");
|
return name.endsWith(".bdk");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Constant <code>DCKFileFilter</code> */
|
/** Constant <code>DCKFileFilter</code>. */
|
||||||
public static final FilenameFilter DCKFileFilter = new FilenameFilter() {
|
public static final FilenameFilter DCK_FILE_FILTER = new FilenameFilter() {
|
||||||
public boolean accept(File dir, String name) {
|
public boolean accept(final File dir, final String name) {
|
||||||
return name.endsWith(".dck");
|
return name.endsWith(".dck");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final FileFilter dckFilter = new FileFilter() {
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final FileFilter DCK_FILTER = new FileFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File f) {
|
public boolean accept(final File f) {
|
||||||
return f.getName().endsWith(".dck") || f.isDirectory();
|
return f.getName().endsWith(".dck") || f.isDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +81,21 @@ public class DeckManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final FileFilter HTML_FILTER = new FileFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(final File f) {
|
||||||
|
return f.getName().endsWith(".html") || f.isDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "Simple Deck File .html";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static final String NAME = "Name";
|
private static final String NAME = "Name";
|
||||||
private static final String DECK_TYPE = "Deck Type";
|
private static final String DECK_TYPE = "Deck Type";
|
||||||
private static final String COMMENT = "Comment";
|
private static final String COMMENT = "Comment";
|
||||||
@@ -67,15 +103,18 @@ public class DeckManager {
|
|||||||
private static final String CSTM_POOL = "Custom Pool";
|
private static final String CSTM_POOL = "Custom Pool";
|
||||||
|
|
||||||
private File deckDir;
|
private File deckDir;
|
||||||
Map<String, Deck> deckMap;
|
private Map<String, Deck> deckMap;
|
||||||
Map<String, Deck[]> draftMap;
|
private Map<String, Deck[]> draftMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Constructor for DeckManager.</p>
|
* <p>
|
||||||
|
* Constructor for DeckManager.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param deckDir a {@link java.io.File} object.
|
* @param deckDir
|
||||||
|
* a {@link java.io.File} object.
|
||||||
*/
|
*/
|
||||||
public DeckManager(File deckDir) {
|
public DeckManager(final File deckDir) {
|
||||||
if (deckDir == null) {
|
if (deckDir == null) {
|
||||||
throw new IllegalArgumentException("No deck directory specified");
|
throw new IllegalArgumentException("No deck directory specified");
|
||||||
}
|
}
|
||||||
@@ -99,96 +138,115 @@ public class DeckManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>isUnique.</p>
|
* <p>
|
||||||
|
* isUnique.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param deckName a {@link java.lang.String} object.
|
* @param deckName
|
||||||
|
* a {@link java.lang.String} object.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
public boolean isUnique(String deckName) {
|
public final boolean isUnique(final String deckName) {
|
||||||
return !deckMap.containsKey(deckName);
|
return !deckMap.containsKey(deckName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>isUniqueDraft.</p>
|
* <p>
|
||||||
|
* isUniqueDraft.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param deckName a {@link java.lang.String} object.
|
* @param deckName
|
||||||
|
* a {@link java.lang.String} object.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
public boolean isUniqueDraft(String deckName) {
|
public final boolean isUniqueDraft(final String deckName) {
|
||||||
return !draftMap.keySet().contains(deckName);
|
return !draftMap.keySet().contains(deckName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>getDeck.</p>
|
* <p>
|
||||||
|
* getDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param deckName a {@link java.lang.String} object.
|
* @param deckName
|
||||||
|
* a {@link java.lang.String} object.
|
||||||
* @return a {@link forge.deck.Deck} object.
|
* @return a {@link forge.deck.Deck} object.
|
||||||
*/
|
*/
|
||||||
public Deck getDeck(String deckName) {
|
public final Deck getDeck(final String deckName) {
|
||||||
return deckMap.get(deckName);
|
return deckMap.get(deckName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>addDeck.</p>
|
* <p>
|
||||||
|
* addDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param deck a {@link forge.deck.Deck} object.
|
* @param deck
|
||||||
|
* a {@link forge.deck.Deck} object.
|
||||||
*/
|
*/
|
||||||
public void addDeck(Deck deck) {
|
public final void addDeck(final Deck deck) {
|
||||||
if (deck.getDeckType().equals(GameType.Draft)) {
|
if (deck.getDeckType().equals(GameType.Draft)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException("DeckManager : addDeck() error, deck type is Draft");
|
||||||
"DeckManager : addDeck() error, deck type is Draft");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deckMap.put(deck.getName(), deck);
|
deckMap.put(deck.getName(), deck);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>deleteDeck.</p>
|
* <p>
|
||||||
|
* deleteDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param deckName a {@link java.lang.String} object.
|
* @param deckName
|
||||||
|
* a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public void deleteDeck(String deckName) {
|
public final void deleteDeck(final String deckName) {
|
||||||
deckMap.remove(deckName);
|
deckMap.remove(deckName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>getDraftDeck.</p>
|
* <p>
|
||||||
|
* getDraftDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param deckName a {@link java.lang.String} object.
|
* @param deckName
|
||||||
|
* a {@link java.lang.String} object.
|
||||||
* @return an array of {@link forge.deck.Deck} objects.
|
* @return an array of {@link forge.deck.Deck} objects.
|
||||||
*/
|
*/
|
||||||
public Deck[] getDraftDeck(String deckName) {
|
public final Deck[] getDraftDeck(final String deckName) {
|
||||||
if (!draftMap.containsKey(deckName)) {
|
if (!draftMap.containsKey(deckName)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException("DeckManager : getDraftDeck() error, deck name not found - " + deckName);
|
||||||
"DeckManager : getDraftDeck() error, deck name not found - " + deckName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return draftMap.get(deckName);
|
return draftMap.get(deckName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>addDraftDeck.</p>
|
* <p>
|
||||||
|
* addDraftDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param deck an array of {@link forge.deck.Deck} objects.
|
* @param deck
|
||||||
|
* an array of {@link forge.deck.Deck} objects.
|
||||||
*/
|
*/
|
||||||
public void addDraftDeck(Deck[] deck) {
|
public final void addDraftDeck(final Deck[] deck) {
|
||||||
checkDraftDeck(deck);
|
checkDraftDeck(deck);
|
||||||
|
|
||||||
draftMap.put(deck[0].toString(), deck);
|
draftMap.put(deck[0].toString(), deck);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>deleteDraftDeck.</p>
|
* <p>
|
||||||
|
* deleteDraftDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param deckName a {@link java.lang.String} object.
|
* @param deckName
|
||||||
|
* a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public void deleteDraftDeck(String deckName) {
|
public final void deleteDraftDeck(final String deckName) {
|
||||||
if (!draftMap.containsKey(deckName)) {
|
if (!draftMap.containsKey(deckName)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException("DeckManager : deleteDraftDeck() error, deck name not found - " + deckName);
|
||||||
"DeckManager : deleteDraftDeck() error, deck name not found - " + deckName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
draftMap.remove(deckName);
|
draftMap.remove(deckName);
|
||||||
@@ -198,32 +256,53 @@ public class DeckManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>checkDraftDeck.</p>
|
* <p>
|
||||||
|
* checkDraftDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param deck an array of {@link forge.deck.Deck} objects.
|
* @param deck
|
||||||
|
* an array of {@link forge.deck.Deck} objects.
|
||||||
*/
|
*/
|
||||||
private void checkDraftDeck(Deck[] deck) {
|
private void checkDraftDeck(final Deck[] deck) {
|
||||||
if (deck == null || deck.length != 8 || deck[0].getName().equals("")
|
if (deck == null || deck.length != 8 || deck[0].getName().equals("")
|
||||||
|| (!deck[0].getDeckType().equals(GameType.Draft))) {
|
|| (!deck[0].getDeckType().equals(GameType.Draft)))
|
||||||
|
{
|
||||||
throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck");
|
throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public Collection<Deck> getDecks() {
|
*
|
||||||
|
* Get Decks.
|
||||||
|
*
|
||||||
|
* @return a Collection<Deck>
|
||||||
|
*/
|
||||||
|
public final Collection<Deck> getDecks() {
|
||||||
return deckMap.values();
|
return deckMap.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public Map<String, Deck[]> getDraftDecks() {
|
*
|
||||||
|
* Get draft decks.
|
||||||
|
*
|
||||||
|
* @return a Map<String, Deck[]>
|
||||||
|
*/
|
||||||
|
public final Map<String, Deck[]> getDraftDecks() {
|
||||||
return new HashMap<String, Deck[]>(draftMap);
|
return new HashMap<String, Deck[]>(draftMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public ArrayList<String> getDeckNames(final GameType deckType) {
|
*
|
||||||
|
* Get names of decks.
|
||||||
|
*
|
||||||
|
* @param deckType
|
||||||
|
* a GameType
|
||||||
|
* @return a ArrayList<String>
|
||||||
|
*/
|
||||||
|
public final ArrayList<String> getDeckNames(final GameType deckType) {
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
|
|
||||||
//only get decks according to the OldGuiNewGame screen option
|
// only get decks according to the OldGuiNewGame screen option
|
||||||
if (deckType.equals(GameType.Draft)) {
|
if (deckType.equals(GameType.Draft)) {
|
||||||
for (String s : getDraftDecks().keySet()) {
|
for (String s : getDraftDecks().keySet()) {
|
||||||
list.add(s);
|
list.add(s);
|
||||||
@@ -241,16 +320,18 @@ public class DeckManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>readAllDecks.</p>
|
* <p>
|
||||||
|
* readAllDecks.
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void readAllDecks() {
|
public final void readAllDecks() {
|
||||||
deckMap.clear();
|
deckMap.clear();
|
||||||
draftMap.clear();
|
draftMap.clear();
|
||||||
|
|
||||||
File[] files;
|
File[] files;
|
||||||
|
|
||||||
List<String> decksThatFailedToLoad = new ArrayList<String>();
|
List<String> decksThatFailedToLoad = new ArrayList<String>();
|
||||||
files = deckDir.listFiles(DCKFileFilter);
|
files = deckDir.listFiles(DCK_FILE_FILTER);
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
try {
|
try {
|
||||||
Deck newDeck = readDeck(file);
|
Deck newDeck = readDeck(file);
|
||||||
@@ -262,41 +343,45 @@ public class DeckManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!decksThatFailedToLoad.isEmpty()) {
|
if (!decksThatFailedToLoad.isEmpty()) {
|
||||||
JOptionPane.showMessageDialog(null, StringUtils.join(decksThatFailedToLoad, System.getProperty("line.separator")),
|
JOptionPane.showMessageDialog(null,
|
||||||
"Some of your decks were not loaded.", JOptionPane.WARNING_MESSAGE);
|
StringUtils.join(decksThatFailedToLoad, System.getProperty("line.separator")),
|
||||||
|
"Some of your decks were not loaded.", JOptionPane.WARNING_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
files = deckDir.listFiles(BDKFileFilter);
|
files = deckDir.listFiles(bdkFileFilter);
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
Deck[] d = new Deck[8];
|
Deck[] d = new Deck[8];
|
||||||
|
|
||||||
boolean gotError = false;
|
boolean gotError = false;
|
||||||
for (int i = 0; i < d.length; i++) {
|
for (int i = 0; i < d.length; i++) {
|
||||||
d[i] = readDeck(new File(file, i + ".dck"));
|
d[i] = readDeck(new File(file, i + ".dck"));
|
||||||
if(d[i] == null) {
|
if (d[i] == null) {
|
||||||
gotError = true;
|
gotError = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gotError)
|
if (!gotError) {
|
||||||
{
|
|
||||||
draftMap.put(d[0].getName(), d);
|
draftMap.put(d[0].getName(), d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>readDeck.</p>
|
* <p>
|
||||||
|
* readDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param deckFile a {@link java.io.File} object.
|
* @param deckFile
|
||||||
|
* a {@link java.io.File} object.
|
||||||
* @return a {@link forge.deck.Deck} object.
|
* @return a {@link forge.deck.Deck} object.
|
||||||
*/
|
*/
|
||||||
public static Deck readDeck(File deckFile) {
|
public static Deck readDeck(final File deckFile) {
|
||||||
|
|
||||||
List<String> lines = FileUtil.readFile(deckFile);
|
List<String> lines = FileUtil.readFile(deckFile);
|
||||||
if (lines.isEmpty()) { return null; }
|
if (lines.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Deck d = new Deck();
|
Deck d = new Deck();
|
||||||
|
|
||||||
@@ -312,29 +397,32 @@ public class DeckManager {
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Iterator<String> findSection(final Iterable<String> lines, final String sectionName)
|
private static Iterator<String> findSection(final Iterable<String> lines, final String sectionName) {
|
||||||
{
|
|
||||||
Iterator<String> lineIterator = lines.iterator();
|
Iterator<String> lineIterator = lines.iterator();
|
||||||
String toSearch = String.format("[%s]", sectionName);
|
String toSearch = String.format("[%s]", sectionName);
|
||||||
while(lineIterator.hasNext()) {
|
while (lineIterator.hasNext()) {
|
||||||
if (toSearch.equalsIgnoreCase(lineIterator.next())) { break; }
|
if (toSearch.equalsIgnoreCase(lineIterator.next())) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lineIterator;
|
return lineIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void readDeckMetadata(final Iterator<String> lineIterator, final Deck d)
|
private static void readDeckMetadata(final Iterator<String> lineIterator, final Deck d) {
|
||||||
{
|
|
||||||
while (lineIterator.hasNext()) {
|
while (lineIterator.hasNext()) {
|
||||||
String line = lineIterator.next();
|
String line = lineIterator.next();
|
||||||
if( line.startsWith("[") ) { break; }
|
if (line.startsWith("[")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
String[] linedata = line.split("=", 2);
|
String[] linedata = line.split("=", 2);
|
||||||
String field = linedata[0].toLowerCase();
|
String field = linedata[0].toLowerCase();
|
||||||
String value = "";
|
String value = "";
|
||||||
|
|
||||||
if (linedata.length > 1)
|
if (linedata.length > 1) {
|
||||||
value = linedata[1];
|
value = linedata[1];
|
||||||
|
}
|
||||||
|
|
||||||
if (NAME.equalsIgnoreCase(field)) {
|
if (NAME.equalsIgnoreCase(field)) {
|
||||||
d.setName(value);
|
d.setName(value);
|
||||||
@@ -360,18 +448,21 @@ public class DeckManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>readDeckOld.</p>
|
* <p>
|
||||||
|
* readDeckOld.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param iterator a {@link java.util.ListIterator} object.
|
* @param iterator
|
||||||
|
* a {@link java.util.ListIterator} object.
|
||||||
* @return a {@link forge.deck.Deck} object.
|
* @return a {@link forge.deck.Deck} object.
|
||||||
*/
|
*/
|
||||||
private static void readDeckOldMetadata(final Iterator<String> iterator, Deck d) {
|
private static void readDeckOldMetadata(final Iterator<String> iterator, final Deck d) {
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
//readDeck name
|
// readDeck name
|
||||||
String name = iterator.next();
|
String name = iterator.next();
|
||||||
|
|
||||||
//readDeck comments
|
// readDeck comments
|
||||||
String comment = null;
|
String comment = null;
|
||||||
while (iterator.hasNext() && (line = iterator.next()) != null && !line.equals("[general]")) {
|
while (iterator.hasNext() && (line = iterator.next()) != null && !line.equals("[general]")) {
|
||||||
if (comment == null) {
|
if (comment == null) {
|
||||||
@@ -381,7 +472,7 @@ public class DeckManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//readDeck deck type
|
// readDeck deck type
|
||||||
|
|
||||||
GameType deckType = iterator.hasNext() ? GameType.smartValueOf(iterator.next()) : GameType.Constructed;
|
GameType deckType = iterator.hasNext() ? GameType.smartValueOf(iterator.next()) : GameType.Constructed;
|
||||||
|
|
||||||
@@ -397,13 +488,17 @@ public class DeckManager {
|
|||||||
|
|
||||||
while (lineIterator.hasNext()) {
|
while (lineIterator.hasNext()) {
|
||||||
String line = lineIterator.next();
|
String line = lineIterator.next();
|
||||||
if (line.startsWith("[")) { break; } // there comes another section
|
if (line.startsWith("[")) {
|
||||||
|
break;
|
||||||
|
} // there comes another section
|
||||||
|
|
||||||
Matcher m = p.matcher(line.trim());
|
Matcher m = p.matcher(line.trim());
|
||||||
m.matches();
|
m.matches();
|
||||||
String sCnt = m.group(2);
|
String sCnt = m.group(2);
|
||||||
String cardName = m.group(3);
|
String cardName = m.group(3);
|
||||||
if (StringUtils.isBlank(cardName)) { continue; }
|
if (StringUtils.isBlank(cardName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int count = sCnt == null ? 1 : parseInt(sCnt);
|
int count = sCnt == null ? 1 : parseInt(sCnt);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
@@ -413,14 +508,21 @@ public class DeckManager {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String deriveFileName(String deckName) {
|
private static String deriveFileName(final String deckName) {
|
||||||
//skips all but the listed characters
|
// skips all but the listed characters
|
||||||
return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", "");
|
return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
//only accepts numbers, letters or dashes up to 20 characters in length
|
// only accepts numbers, letters or dashes up to 20 characters in length
|
||||||
public static String cleanDeckName(String in)
|
/**
|
||||||
{
|
*
|
||||||
|
* Clean deck name.
|
||||||
|
*
|
||||||
|
* @param in
|
||||||
|
* a String
|
||||||
|
* @return a String
|
||||||
|
*/
|
||||||
|
public static String cleanDeckName(final String in) {
|
||||||
char[] c = in.toCharArray();
|
char[] c = in.toCharArray();
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < c.length && i < 20; i++) {
|
for (int i = 0; i < c.length && i < 20; i++) {
|
||||||
@@ -431,24 +533,45 @@ public class DeckManager {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File makeFileName(String deckName, GameType deckType)
|
/**
|
||||||
{
|
*
|
||||||
|
* Make file name.
|
||||||
|
*
|
||||||
|
* @param deckName
|
||||||
|
* a String
|
||||||
|
* @param deckType
|
||||||
|
* a GameType
|
||||||
|
* @return a File
|
||||||
|
*/
|
||||||
|
public static File makeFileName(final String deckName, final GameType deckType) {
|
||||||
File path = ForgeProps.getFile(NewConstants.NEW_DECKS);
|
File path = ForgeProps.getFile(NewConstants.NEW_DECKS);
|
||||||
if (deckType == GameType.Draft)
|
if (deckType == GameType.Draft) {
|
||||||
return new File(path, deriveFileName(deckName) + ".bdk");
|
return new File(path, deriveFileName(deckName) + ".bdk");
|
||||||
else
|
} else {
|
||||||
return new File(path, deriveFileName(deckName) + ".dck");
|
return new File(path, deriveFileName(deckName) + ".dck");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File makeFileName(Deck deck)
|
/**
|
||||||
{
|
*
|
||||||
|
* Make file name.
|
||||||
|
*
|
||||||
|
* @param deck
|
||||||
|
* a Deck
|
||||||
|
* @return a File
|
||||||
|
*/
|
||||||
|
public static File makeFileName(final Deck deck) {
|
||||||
return makeFileName(deck.getName(), deck.getDeckType());
|
return makeFileName(deck.getName(), deck.getDeckType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>writeAllDecks.</p>
|
*
|
||||||
|
* Write draft Decks.
|
||||||
|
*
|
||||||
|
* @param drafts
|
||||||
|
* a Deck[]
|
||||||
*/
|
*/
|
||||||
public static void writeDraftDecks(Deck[] drafts) {
|
public static void writeDraftDecks(final Deck[] drafts) {
|
||||||
try {
|
try {
|
||||||
File f = makeFileName(drafts[0]);
|
File f = makeFileName(drafts[0]);
|
||||||
f.mkdir();
|
f.mkdir();
|
||||||
@@ -458,7 +581,6 @@ public class DeckManager {
|
|||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ErrorViewer.showError(ex);
|
ErrorViewer.showError(ex);
|
||||||
throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage());
|
throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage());
|
||||||
@@ -466,11 +588,16 @@ public class DeckManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>writeDeck.</p>
|
* <p>
|
||||||
|
* writeDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param d a {@link forge.deck.Deck} object.
|
* @param d
|
||||||
* @param out a {@link java.io.BufferedWriter} object.
|
* a {@link forge.deck.Deck} object.
|
||||||
* @throws java.io.IOException if any.
|
* @param out
|
||||||
|
* a {@link java.io.BufferedWriter} object.
|
||||||
|
* @throws java.io.IOException
|
||||||
|
* if any.
|
||||||
*/
|
*/
|
||||||
private static void writeDeck(final Deck d, final BufferedWriter out) throws IOException {
|
private static void writeDeck(final Deck d, final BufferedWriter out) throws IOException {
|
||||||
out.write(format("[metadata]%n"));
|
out.write(format("[metadata]%n"));
|
||||||
@@ -478,10 +605,16 @@ public class DeckManager {
|
|||||||
out.write(format("%s=%s%n", NAME, d.getName().replaceAll("\n", "")));
|
out.write(format("%s=%s%n", NAME, d.getName().replaceAll("\n", "")));
|
||||||
out.write(format("%s=%s%n", DECK_TYPE, d.getDeckType()));
|
out.write(format("%s=%s%n", DECK_TYPE, d.getDeckType()));
|
||||||
// these are optional
|
// these are optional
|
||||||
if (d.getComment() != null) { out.write(format("%s=%s%n", COMMENT, d.getComment().replaceAll("\n", ""))); }
|
if (d.getComment() != null) {
|
||||||
if (d.getPlayerType() != null) { out.write(format("%s=%s%n", PLAYER, d.getPlayerType())); }
|
out.write(format("%s=%s%n", COMMENT, d.getComment().replaceAll("\n", "")));
|
||||||
|
}
|
||||||
|
if (d.getPlayerType() != null) {
|
||||||
|
out.write(format("%s=%s%n", PLAYER, d.getPlayerType()));
|
||||||
|
}
|
||||||
|
|
||||||
if (d.isCustomPool()) { out.write(format("%s=%s%n", CSTM_POOL, "true")); }
|
if (d.isCustomPool()) {
|
||||||
|
out.write(format("%s=%s%n", CSTM_POOL, "true"));
|
||||||
|
}
|
||||||
|
|
||||||
out.write(format("%s%n", "[main]"));
|
out.write(format("%s%n", "[main]"));
|
||||||
writeCardPool(d.getMain(), out);
|
writeCardPool(d.getMain(), out);
|
||||||
@@ -490,8 +623,57 @@ public class DeckManager {
|
|||||||
writeCardPool(d.getSideboard(), out);
|
writeCardPool(d.getSideboard(), out);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeCardPool(final ItemPoolView<CardPrinted> pool, final BufferedWriter out) throws IOException
|
/**
|
||||||
{
|
* <p>
|
||||||
|
* writeDeck.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param d
|
||||||
|
* a {@link forge.deck.Deck} object.
|
||||||
|
* @param out
|
||||||
|
* a {@link java.io.BufferedWriter} object.
|
||||||
|
* @throws java.io.IOException
|
||||||
|
* if any.
|
||||||
|
*/
|
||||||
|
private static void writeDeckHtml(final Deck d, final BufferedWriter out) throws IOException {
|
||||||
|
Template temp = null;
|
||||||
|
|
||||||
|
/* Create and adjust the configuration */
|
||||||
|
Configuration cfg = new Configuration();
|
||||||
|
try {
|
||||||
|
cfg.setClassForTemplateLoading(d.getClass(), "/");
|
||||||
|
cfg.setObjectWrapper(new DefaultObjectWrapper());
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------- */
|
||||||
|
/* You usually do these for many times in the application life-cycle: */
|
||||||
|
|
||||||
|
/* Get or create a template */
|
||||||
|
temp = cfg.getTemplate("proxy-template.ftl");
|
||||||
|
|
||||||
|
|
||||||
|
/* Create a data-model */
|
||||||
|
Map root = new HashMap();
|
||||||
|
root.put("title", d.getName());
|
||||||
|
List list = new ArrayList();
|
||||||
|
for (Card card : d.getMain().toForgeCardList().toArray()) {
|
||||||
|
//System.out.println(card.getSets().get(0).URL);
|
||||||
|
list.add(card.getSets().get(0).URL);
|
||||||
|
}
|
||||||
|
root.put("urls", list);
|
||||||
|
|
||||||
|
/* Merge data-model with template */
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
temp.process(root, out);
|
||||||
|
out.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println(e.toString());
|
||||||
|
} catch (TemplateException e) {
|
||||||
|
System.out.println(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeCardPool(final ItemPoolView<CardPrinted> pool,
|
||||||
|
final BufferedWriter out) throws IOException {
|
||||||
List<Entry<CardPrinted, Integer>> main2sort = pool.getOrderedList();
|
List<Entry<CardPrinted, Integer>> main2sort = pool.getOrderedList();
|
||||||
Collections.sort(main2sort, TableSorter.byNameThenSet);
|
Collections.sort(main2sort, TableSorter.byNameThenSet);
|
||||||
for (Entry<CardPrinted, Integer> e : main2sort) {
|
for (Entry<CardPrinted, Integer> e : main2sort) {
|
||||||
@@ -505,14 +687,17 @@ public class DeckManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>writeDeck.</p>
|
* <p>
|
||||||
|
* writeDeck.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param d a {@link forge.deck.Deck} object.
|
* @param d
|
||||||
* @param f a {@link java.io.File} object.
|
* a {@link forge.deck.Deck} object.
|
||||||
|
* @param f
|
||||||
|
* a {@link java.io.File} object.
|
||||||
*/
|
*/
|
||||||
public static void writeDeck(Deck d, File f) {
|
public static void writeDeck(final Deck d, final File f) {
|
||||||
try {
|
try {
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter(f));
|
BufferedWriter writer = new BufferedWriter(new FileWriter(f));
|
||||||
writeDeck(d, writer);
|
writeDeck(d, writer);
|
||||||
@@ -523,4 +708,23 @@ public class DeckManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Write deck to HTML.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param d
|
||||||
|
* a {@link forge.deck.Deck} object.
|
||||||
|
* @param f
|
||||||
|
* a {@link java.io.File} object.
|
||||||
|
*/
|
||||||
|
public static void writeDeckHtml(final Deck d, final File f) {
|
||||||
|
try {
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter(f));
|
||||||
|
writeDeckHtml(d, writer);
|
||||||
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,23 @@
|
|||||||
package forge.gui.deckeditor;
|
package forge.gui.deckeditor;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JMenu;
|
||||||
|
import javax.swing.JMenuBar;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.CardList;
|
import forge.CardList;
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
@@ -14,34 +32,21 @@ import forge.item.CardPrinted;
|
|||||||
import forge.item.ItemPool;
|
import forge.item.ItemPool;
|
||||||
import forge.properties.ForgeProps;
|
import forge.properties.ForgeProps;
|
||||||
import forge.properties.NewConstants;
|
import forge.properties.NewConstants;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.channels.FileChannel;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
|
||||||
import javax.swing.JMenu;
|
|
||||||
import javax.swing.JMenuBar;
|
|
||||||
import javax.swing.JMenuItem;
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Gui_DeckEditor_Menu class.</p>
|
* <p>
|
||||||
|
* Gui_DeckEditor_Menu class.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants {
|
public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants {
|
||||||
|
|
||||||
/** Constant <code>serialVersionUID=-4037993759604768755L</code> */
|
/** Constant <code>serialVersionUID=-4037993759604768755L</code>. */
|
||||||
private static final long serialVersionUID = -4037993759604768755L;
|
private static final long serialVersionUID = -4037993759604768755L;
|
||||||
|
|
||||||
/** Constant <code>previousDirectory</code> */
|
/** Constant <code>previousDirectory</code>. */
|
||||||
private static File previousDirectory = null;
|
private static File previousDirectory = null;
|
||||||
|
|
||||||
private DeckManager deckManager;
|
private DeckManager deckManager;
|
||||||
@@ -53,24 +58,34 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
|
|
||||||
private Command exitCommand;
|
private Command exitCommand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
public DeckEditorCommonMenu(final DeckDisplay in_display, final DeckManager dckManager, final Command exit) {
|
* Menu for Deck Editor.
|
||||||
deckDisplay = in_display;
|
*
|
||||||
|
* @param inDisplay
|
||||||
|
* a DeckDisplay
|
||||||
|
* @param dckManager
|
||||||
|
* a DeckManager
|
||||||
|
* @param exit
|
||||||
|
* a Command
|
||||||
|
*/
|
||||||
|
public DeckEditorCommonMenu(final DeckDisplay inDisplay, final DeckManager dckManager, final Command exit) {
|
||||||
|
deckDisplay = inDisplay;
|
||||||
exitCommand = exit;
|
exitCommand = exit;
|
||||||
deckManager = dckManager;
|
deckManager = dckManager;
|
||||||
|
|
||||||
//this is added just to make save() and saveAs() work ok
|
// this is added just to make save() and saveAs() work ok
|
||||||
//when first started up, just a silly patch
|
// when first started up, just a silly patch
|
||||||
setDeckData("", true);
|
setDeckData("", true);
|
||||||
|
|
||||||
setupMenu();
|
setupMenu();
|
||||||
setupSortMenu();
|
setupSortMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>setupSortMenu.</p>
|
* <p>
|
||||||
|
* setupSortMenu.
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
private void setupSortMenu() {
|
private void setupSortMenu() {
|
||||||
JMenuItem name = new JMenuItem("Card Name");
|
JMenuItem name = new JMenuItem("Card Name");
|
||||||
@@ -96,11 +111,12 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 0 1 2 3 4 5 6
|
// 0 1 2 3 4 5 6
|
||||||
//private String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity"};
|
// private String column[] = {"Qty", "Name", "Cost", "Color", "Type",
|
||||||
|
// "Stats", "Rarity"};
|
||||||
cost.addActionListener(new ActionListener() {
|
cost.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(final ActionEvent ev) {
|
public void actionPerformed(final ActionEvent ev) {
|
||||||
((DeckEditorCommon) deckDisplay).getTopTableModel().sort(4).sort(3).sort(2);
|
((DeckEditorCommon) deckDisplay).getTopTableModel().sort(4).sort(3).sort(2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -124,15 +140,22 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
|
|
||||||
rarity.addActionListener(new ActionListener() {
|
rarity.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(final ActionEvent ev) {
|
public void actionPerformed(final ActionEvent ev) {
|
||||||
//sort by cost, type, color, rarity
|
// sort by cost, type, color, rarity
|
||||||
((DeckEditorCommon) deckDisplay).getTopTableModel().sort(2).sort(4).sort(3).sort(6);
|
((DeckEditorCommon) deckDisplay).getTopTableModel().sort(2).sort(4).sort(3).sort(6);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} //setupSortMenu()
|
} // setupSortMenu()
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param careAboutOldDeck
|
||||||
|
* a boolean
|
||||||
|
*/
|
||||||
public void newConstructed(final boolean careAboutOldDeck) {
|
public void newConstructed(final boolean careAboutOldDeck) {
|
||||||
if (careAboutOldDeck && !canLeaveCurrentDeck()) { return; }
|
if (careAboutOldDeck && !canLeaveCurrentDeck()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setDeckData("", true);
|
setDeckData("", true);
|
||||||
|
|
||||||
@@ -140,7 +163,9 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void newRandomConstructed() {
|
private void newRandomConstructed() {
|
||||||
if (!canLeaveCurrentDeck()) { return; }
|
if (!canLeaveCurrentDeck()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setDeckData("", false);
|
setDeckData("", false);
|
||||||
|
|
||||||
@@ -148,7 +173,9 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
CardList random = new CardList(forge.AllZone.getCardFactory().getRandomCombinationWithoutRepetition(15 * 5));
|
CardList random = new CardList(forge.AllZone.getCardFactory().getRandomCombinationWithoutRepetition(15 * 5));
|
||||||
|
|
||||||
ItemPool<CardPrinted> cpRandom = new ItemPool<CardPrinted>(CardPrinted.class);
|
ItemPool<CardPrinted> cpRandom = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||||
for (Card c : random) { cpRandom.add(CardDb.instance().getCard(c)); }
|
for (Card c : random) {
|
||||||
|
cpRandom.add(CardDb.instance().getCard(c));
|
||||||
|
}
|
||||||
cpRandom.add(CardDb.instance().getCard("Forest"));
|
cpRandom.add(CardDb.instance().getCard("Forest"));
|
||||||
cpRandom.add(CardDb.instance().getCard("Island"));
|
cpRandom.add(CardDb.instance().getCard("Island"));
|
||||||
cpRandom.add(CardDb.instance().getCard("Plains"));
|
cpRandom.add(CardDb.instance().getCard("Plains"));
|
||||||
@@ -160,22 +187,25 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void newGenerateConstructed() {
|
private void newGenerateConstructed() {
|
||||||
if (!canLeaveCurrentDeck()) { return; }
|
if (!canLeaveCurrentDeck()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setDeckData("", false);
|
setDeckData("", false);
|
||||||
|
|
||||||
GenerateConstructedDeck gen = new GenerateConstructedDeck();
|
GenerateConstructedDeck gen = new GenerateConstructedDeck();
|
||||||
|
|
||||||
ItemPool<CardPrinted> generated = new ItemPool<CardPrinted>(CardPrinted.class);
|
ItemPool<CardPrinted> generated = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||||
for (Card c : gen.generateDeck()) { generated.add(CardDb.instance().getCard(c)); }
|
for (Card c : gen.generateDeck()) {
|
||||||
|
generated.add(CardDb.instance().getCard(c));
|
||||||
|
}
|
||||||
deckDisplay.setDeck(null, generated, GameType.Constructed);
|
deckDisplay.setDeck(null, generated, GameType.Constructed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private File getImportFilename() {
|
private File getImportFilename() {
|
||||||
JFileChooser chooser = new JFileChooser(previousDirectory);
|
JFileChooser chooser = new JFileChooser(previousDirectory);
|
||||||
|
|
||||||
chooser.addChoosableFileFilter(DeckManager.dckFilter);
|
chooser.addChoosableFileFilter(DeckManager.DCK_FILTER);
|
||||||
int returnVal = chooser.showOpenDialog(null);
|
int returnVal = chooser.showOpenDialog(null);
|
||||||
|
|
||||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||||
@@ -184,8 +214,7 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} //openFileDialog()
|
} // openFileDialog()
|
||||||
|
|
||||||
|
|
||||||
private void importDeck() {
|
private void importDeck() {
|
||||||
File file = getImportFilename();
|
File file = getImportFilename();
|
||||||
@@ -218,11 +247,15 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>exportDeck.</p>
|
* <p>
|
||||||
|
* exportDeck.
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
private void exportDeck() {
|
private void exportDeck() {
|
||||||
File filename = getExportFilename();
|
File filename = getExportFilename();
|
||||||
if (filename == null) { return; }
|
if (filename == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Deck deck = getDeck();
|
Deck deck = getDeck();
|
||||||
try {
|
try {
|
||||||
@@ -233,12 +266,11 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private File getExportFilename() {
|
private File getExportFilename() {
|
||||||
JFileChooser save = new JFileChooser(previousDirectory);
|
JFileChooser save = new JFileChooser(previousDirectory);
|
||||||
save.setDialogTitle("Export Deck Filename");
|
save.setDialogTitle("Export Deck Filename");
|
||||||
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||||
save.setFileFilter(DeckManager.dckFilter);
|
save.setFileFilter(DeckManager.DCK_FILTER);
|
||||||
|
|
||||||
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||||
File file = save.getSelectedFile();
|
File file = save.getSelectedFile();
|
||||||
@@ -251,18 +283,68 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openDeck(GameType gameType) {
|
/**
|
||||||
if (!canLeaveCurrentDeck()) { return; }
|
* <p>
|
||||||
|
* Generate Proxy for a Deck.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
private void generateProxies() {
|
||||||
|
File filename = getProxiesFilename();
|
||||||
|
if (filename == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String name = getUserInput_OpenDeck(gameType);
|
Deck deck = getDeck();
|
||||||
|
try {
|
||||||
|
DeckManager.writeDeckHtml(deck, filename);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ErrorViewer.showError(ex);
|
||||||
|
throw new RuntimeException("Gui_DeckEditor_Menu : printProxies() error, " + ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (StringUtils.isBlank(name)) { return; }
|
private File getProxiesFilename() {
|
||||||
|
JFileChooser save = new JFileChooser(previousDirectory);
|
||||||
|
save.setDialogTitle("Proxy HTML Filename");
|
||||||
|
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||||
|
save.setFileFilter(DeckManager.HTML_FILTER);
|
||||||
|
|
||||||
|
if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||||
|
File file = save.getSelectedFile();
|
||||||
|
String check = file.getAbsolutePath();
|
||||||
|
|
||||||
|
previousDirectory = file.getParentFile();
|
||||||
|
|
||||||
|
return check.endsWith(".html") ? file : new File(check + ".html");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openDeck(final GameType gameType) {
|
||||||
|
if (!canLeaveCurrentDeck()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = getUserInputOpenDeck(gameType);
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(name)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Deck deck = gameType == GameType.Draft ? deckManager.getDraftDeck(name)[0] : deckManager.getDeck(name);
|
Deck deck = gameType == GameType.Draft ? deckManager.getDraftDeck(name)[0] : deckManager.getDeck(name);
|
||||||
showDeck(deck, gameType);
|
showDeck(deck, gameType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void showDeck(final Deck deck, final GameType gameType) {
|
/**
|
||||||
|
*
|
||||||
|
* showDeck.
|
||||||
|
*
|
||||||
|
* @param deck
|
||||||
|
* a Deck
|
||||||
|
* @param gameType
|
||||||
|
* a GameType
|
||||||
|
*/
|
||||||
|
public void showDeck(final Deck deck, final GameType gameType) {
|
||||||
setDeckData(deck.getName(), true);
|
setDeckData(deck.getName(), true);
|
||||||
if (gameType.isLimited()) {
|
if (gameType.isLimited()) {
|
||||||
deckDisplay.setDeck(deck.getSideboard(), deck.getMain(), gameType);
|
deckDisplay.setDeck(deck.getSideboard(), deck.getMain(), gameType);
|
||||||
@@ -271,8 +353,6 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void save() {
|
private void save() {
|
||||||
|
|
||||||
if (currentDeckName.equals("")) {
|
if (currentDeckName.equals("")) {
|
||||||
@@ -283,12 +363,12 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
Deck deck = getDeck();
|
Deck deck = getDeck();
|
||||||
if (deckDisplay.getGameType().equals(GameType.Draft)) {
|
if (deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||||
setDeckData(currentDeckName, true);
|
setDeckData(currentDeckName, true);
|
||||||
//write booster deck
|
// write booster deck
|
||||||
Deck[] all = deckManager.getDraftDeck(currentDeckName);
|
Deck[] all = deckManager.getDraftDeck(currentDeckName);
|
||||||
all[0] = deck;
|
all[0] = deck;
|
||||||
deckManager.addDraftDeck(all);
|
deckManager.addDraftDeck(all);
|
||||||
DeckManager.writeDraftDecks(all);
|
DeckManager.writeDraftDecks(all);
|
||||||
} else { //constructed or sealed
|
} else { // constructed or sealed
|
||||||
setDeckData(currentDeckName, true);
|
setDeckData(currentDeckName, true);
|
||||||
deckManager.addDeck(deck);
|
deckManager.addDeck(deck);
|
||||||
DeckManager.writeDeck(deck, DeckManager.makeFileName(deck));
|
DeckManager.writeDeck(deck, DeckManager.makeFileName(deck));
|
||||||
@@ -299,12 +379,14 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
private void saveAs() {
|
private void saveAs() {
|
||||||
String name = getDeckNameFromDialog();
|
String name = getDeckNameFromDialog();
|
||||||
|
|
||||||
if (name.equals("")) { return; }
|
if (name.equals("")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
setDeckData(name, true);
|
setDeckData(name, true);
|
||||||
|
|
||||||
Deck deck = getDeck();
|
Deck deck = getDeck();
|
||||||
if (deckDisplay.getGameType().equals(GameType.Draft)) {
|
if (deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||||
//MUST copy array
|
// MUST copy array
|
||||||
Deck[] read = deckManager.getDraftDeck(currentDeckName);
|
Deck[] read = deckManager.getDraftDeck(currentDeckName);
|
||||||
Deck[] all = new Deck[read.length];
|
Deck[] all = new Deck[read.length];
|
||||||
|
|
||||||
@@ -313,21 +395,24 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
all[0] = deck;
|
all[0] = deck;
|
||||||
deckManager.addDraftDeck(all);
|
deckManager.addDraftDeck(all);
|
||||||
DeckManager.writeDraftDecks(all);
|
DeckManager.writeDraftDecks(all);
|
||||||
} else {//constructed and sealed
|
} else { // constructed and sealed
|
||||||
deckManager.addDeck(deck);
|
deckManager.addDeck(deck);
|
||||||
DeckManager.writeDeck(deck, DeckManager.makeFileName(deck));
|
DeckManager.writeDeck(deck, DeckManager.makeFileName(deck));
|
||||||
}
|
}
|
||||||
isDeckSaved = true;
|
isDeckSaved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void delete() {
|
private void delete() {
|
||||||
if (StringUtils.isBlank(currentDeckName)) { return; }
|
if (StringUtils.isBlank(currentDeckName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int n = JOptionPane.showConfirmDialog(null, "Do you want to delete this deck " + currentDeckName + " ?",
|
int n = JOptionPane.showConfirmDialog(null, "Do you want to delete this deck " + currentDeckName + " ?",
|
||||||
"Delete", JOptionPane.YES_NO_OPTION);
|
"Delete", JOptionPane.YES_NO_OPTION);
|
||||||
|
|
||||||
if (n == JOptionPane.NO_OPTION) { return; }
|
if (n == JOptionPane.NO_OPTION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (deckDisplay.getGameType().equals(GameType.Draft)) {
|
if (deckDisplay.getGameType().equals(GameType.Draft)) {
|
||||||
deckManager.deleteDraftDeck(currentDeckName);
|
deckManager.deleteDraftDeck(currentDeckName);
|
||||||
@@ -339,18 +424,32 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
deckDisplay.setDeck(null, null, deckDisplay.getGameType());
|
deckDisplay.setDeck(null, null, deckDisplay.getGameType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void close() {
|
/**
|
||||||
if (!canLeaveCurrentDeck()) { return; }
|
*
|
||||||
|
* close window.
|
||||||
|
*/
|
||||||
|
public void close() {
|
||||||
|
if (!canLeaveCurrentDeck()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
exitCommand.execute();
|
exitCommand.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canLeaveCurrentDeck() {
|
private boolean canLeaveCurrentDeck() {
|
||||||
if (isSaved()) { return true; }
|
if (isSaved()) {
|
||||||
String message = String.format("Do you wish to save changes you made to your current deck '%s'?", currentDeckName);
|
return true;
|
||||||
int choice = JOptionPane.showConfirmDialog((Component) deckDisplay, message,
|
}
|
||||||
"You have unsaved changes in your deck", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
|
String message = String.format("Do you wish to save changes you made to your current deck '%s'?",
|
||||||
if (JOptionPane.CANCEL_OPTION == choice) { return false; }
|
currentDeckName);
|
||||||
if (JOptionPane.NO_OPTION == choice) { return true; }
|
int choice = JOptionPane
|
||||||
|
.showConfirmDialog((Component) deckDisplay, message, "You have unsaved changes in your deck",
|
||||||
|
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||||
|
if (JOptionPane.CANCEL_OPTION == choice) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (JOptionPane.NO_OPTION == choice) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Deck deck = getDeck();
|
Deck deck = getDeck();
|
||||||
deck.setName(currentDeckName);
|
deck.setName(currentDeckName);
|
||||||
@@ -371,31 +470,54 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
deckDisplay.setTitle("Deck Editor : " + currentDeckName);
|
deckDisplay.setTitle("Deck Editor : " + currentDeckName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDeckName() { return currentDeckName; }
|
/**
|
||||||
public boolean isSaved() { return isDeckSaved; }
|
*
|
||||||
|
* Get Deck Name.
|
||||||
|
*
|
||||||
|
* @return a String
|
||||||
|
*/
|
||||||
|
public String getDeckName() {
|
||||||
|
return currentDeckName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>getUserInput_GetDeckName.</p>
|
*
|
||||||
|
* Is Saved.
|
||||||
|
*
|
||||||
|
* @return a boolean
|
||||||
|
*/
|
||||||
|
public boolean isSaved() {
|
||||||
|
return isDeckSaved;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* getUserInput_GetDeckName.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a {@link java.lang.String} object.
|
* @return a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
private String getDeckNameFromDialog() {
|
private String getDeckNameFromDialog() {
|
||||||
Object o = JOptionPane.showInputDialog(null, "Save As", "Deck Name", JOptionPane.OK_CANCEL_OPTION);
|
Object o = JOptionPane.showInputDialog(null, "Save As", "Deck Name", JOptionPane.OK_CANCEL_OPTION);
|
||||||
|
|
||||||
if (o == null) { return ""; }
|
if (o == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
String deckName = DeckManager.cleanDeckName(o.toString());
|
String deckName = DeckManager.cleanDeckName(o.toString());
|
||||||
boolean isDraft = deckDisplay.getGameType() == GameType.Draft;
|
boolean isDraft = deckDisplay.getGameType() == GameType.Draft;
|
||||||
boolean isUniqueName = isDraft ? deckManager.isUniqueDraft(deckName) : deckManager.isUnique(deckName);
|
boolean isUniqueName = isDraft ? deckManager.isUniqueDraft(deckName) : deckManager.isUnique(deckName);
|
||||||
boolean isGoodName = isUniqueName && StringUtils.isNotBlank(deckName);
|
boolean isGoodName = isUniqueName && StringUtils.isNotBlank(deckName);
|
||||||
|
|
||||||
if (isGoodName) { return deckName; }
|
if (isGoodName) {
|
||||||
|
return deckName;
|
||||||
|
}
|
||||||
|
|
||||||
JOptionPane.showMessageDialog(null, "Please pick another deck name, another deck currently has that name.");
|
JOptionPane.showMessageDialog(null, "Please pick another deck name, another deck currently has that name.");
|
||||||
return getDeckNameFromDialog();
|
return getDeckNameFromDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getUserInput_OpenDeck(final GameType deckType) {
|
private String getUserInputOpenDeck(final GameType deckType) {
|
||||||
ArrayList<String> choices = deckManager.getDeckNames(deckType);
|
ArrayList<String> choices = deckManager.getDeckNames(deckType);
|
||||||
if (choices.isEmpty()) {
|
if (choices.isEmpty()) {
|
||||||
JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE);
|
JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE);
|
||||||
@@ -406,9 +528,12 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
return o == null ? null : o.toString();
|
return o == null ? null : o.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// deck.setName(currentDeckName);
|
// deck.setName(currentDeckName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Notify of a Deck Change.
|
||||||
|
*/
|
||||||
public void notifyDeckChange() {
|
public void notifyDeckChange() {
|
||||||
isDeckSaved = false;
|
isDeckSaved = false;
|
||||||
}
|
}
|
||||||
@@ -416,24 +541,22 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
private void setupMenu() {
|
private void setupMenu() {
|
||||||
JMenuItem newConstructed = new JMenuItem("New Deck - Constructed");
|
JMenuItem newConstructed = new JMenuItem("New Deck - Constructed");
|
||||||
|
|
||||||
//JMenuItem newSealed = new JMenuItem("New Deck - Sealed");
|
// JMenuItem newSealed = new JMenuItem("New Deck - Sealed");
|
||||||
//JMenuItem newDraft = new JMenuItem("New Deck - Draft");
|
// JMenuItem newDraft = new JMenuItem("New Deck - Draft");
|
||||||
|
|
||||||
JMenuItem newRandomConstructed = new JMenuItem("New Deck - Generate Random Constructed Cardpool");
|
JMenuItem newRandomConstructed = new JMenuItem("New Deck - Generate Random Constructed Cardpool");
|
||||||
JMenuItem newGenerateConstructed = new JMenuItem("New Deck - Generate Constructed Deck");
|
JMenuItem newGenerateConstructed = new JMenuItem("New Deck - Generate Constructed Deck");
|
||||||
|
|
||||||
|
|
||||||
JMenuItem importDeck = new JMenuItem("Import Deck");
|
JMenuItem importDeck = new JMenuItem("Import Deck");
|
||||||
JMenuItem exportDeck = new JMenuItem("Export Deck");
|
JMenuItem exportDeck = new JMenuItem("Export Deck");
|
||||||
// JMenuItem downloadDeck = new JMenuItem("Download Deck");
|
// JMenuItem downloadDeck = new JMenuItem("Download Deck");
|
||||||
|
|
||||||
|
|
||||||
JMenuItem openConstructed = new JMenuItem("Open Deck - Constructed");
|
JMenuItem openConstructed = new JMenuItem("Open Deck - Constructed");
|
||||||
JMenuItem openSealed = new JMenuItem("Open Deck - Sealed");
|
JMenuItem openSealed = new JMenuItem("Open Deck - Sealed");
|
||||||
JMenuItem openDraft = new JMenuItem("Open Deck - Draft");
|
JMenuItem openDraft = new JMenuItem("Open Deck - Draft");
|
||||||
|
|
||||||
//newDraftItem = newDraft;
|
// newDraftItem = newDraft;
|
||||||
//newDraftItem.setEnabled(false);
|
// newDraftItem.setEnabled(false);
|
||||||
|
|
||||||
JMenuItem save = new JMenuItem("Save");
|
JMenuItem save = new JMenuItem("Save");
|
||||||
JMenuItem saveAs = new JMenuItem("Save As");
|
JMenuItem saveAs = new JMenuItem("Save As");
|
||||||
@@ -443,8 +566,8 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
JMenu fileMenu = new JMenu("Deck Actions");
|
JMenu fileMenu = new JMenu("Deck Actions");
|
||||||
fileMenu.add(newConstructed);
|
fileMenu.add(newConstructed);
|
||||||
|
|
||||||
//fileMenu.add(newSealed);
|
// fileMenu.add(newSealed);
|
||||||
//fileMenu.add(newDraft);
|
// fileMenu.add(newDraft);
|
||||||
fileMenu.addSeparator();
|
fileMenu.addSeparator();
|
||||||
|
|
||||||
fileMenu.add(openConstructed);
|
fileMenu.add(openConstructed);
|
||||||
@@ -454,7 +577,25 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
|
|
||||||
fileMenu.add(importDeck);
|
fileMenu.add(importDeck);
|
||||||
fileMenu.add(exportDeck);
|
fileMenu.add(exportDeck);
|
||||||
//fileMenu.add(downloadDeck);
|
|
||||||
|
JMenuItem generateProxies = new JMenuItem("Generate Proxies...");
|
||||||
|
fileMenu.add(generateProxies);
|
||||||
|
|
||||||
|
generateProxies.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(final ActionEvent ev) {
|
||||||
|
try {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
generateProxies();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ErrorViewer.showError(ex);
|
||||||
|
throw new RuntimeException("Gui_DeckEditor_Menu : generateProxies() error - " + ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// fileMenu.add(downloadDeck);
|
||||||
fileMenu.addSeparator();
|
fileMenu.addSeparator();
|
||||||
|
|
||||||
fileMenu.add(newRandomConstructed);
|
fileMenu.add(newRandomConstructed);
|
||||||
@@ -470,7 +611,7 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
|
|
||||||
this.add(fileMenu);
|
this.add(fileMenu);
|
||||||
|
|
||||||
//add listeners
|
// add listeners
|
||||||
exportDeck.addActionListener(new ActionListener() {
|
exportDeck.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(final ActionEvent ev) {
|
public void actionPerformed(final ActionEvent ev) {
|
||||||
try {
|
try {
|
||||||
@@ -486,7 +627,6 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
importDeck.addActionListener(new ActionListener() {
|
importDeck.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(final ActionEvent ev) {
|
public void actionPerformed(final ActionEvent ev) {
|
||||||
try {
|
try {
|
||||||
@@ -502,21 +642,15 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* downloadDeck.addActionListener(new ActionListener() {
|
/*
|
||||||
public void actionPerformed(final ActionEvent ev) {
|
* downloadDeck.addActionListener(new ActionListener() { public void
|
||||||
try {
|
* actionPerformed(final ActionEvent ev) { try {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
* SwingUtilities.invokeLater(new Runnable() { public void run() {
|
||||||
public void run() {
|
* downloadDeck(); } }); } catch (Exception ex) {
|
||||||
downloadDeck();
|
* ErrorViewer.showError(ex); throw new
|
||||||
}
|
* RuntimeException("Gui_DeckEditor_Menu : downloadDeck() error - " +
|
||||||
});
|
* ex); } } });
|
||||||
} catch (Exception ex) {
|
*/
|
||||||
ErrorViewer.showError(ex);
|
|
||||||
throw new RuntimeException("Gui_DeckEditor_Menu : downloadDeck() error - " + ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
newConstructed.addActionListener(new ActionListener() {
|
newConstructed.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(final ActionEvent ev) {
|
public void actionPerformed(final ActionEvent ev) {
|
||||||
try {
|
try {
|
||||||
@@ -532,7 +666,6 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
newRandomConstructed.addActionListener(new ActionListener() {
|
newRandomConstructed.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(final ActionEvent ev) {
|
public void actionPerformed(final ActionEvent ev) {
|
||||||
try {
|
try {
|
||||||
@@ -548,7 +681,6 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
newGenerateConstructed.addActionListener(new ActionListener() {
|
newGenerateConstructed.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(final ActionEvent ev) {
|
public void actionPerformed(final ActionEvent ev) {
|
||||||
try {
|
try {
|
||||||
@@ -668,5 +800,5 @@ public final class DeckEditorCommonMenu extends JMenuBar implements NewConstants
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}//setupMenu()
|
} // setupMenu()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,18 +7,40 @@ import java.util.Map.Entry;
|
|||||||
/**
|
/**
|
||||||
* <p>CardPool class.</p>
|
* <p>CardPool class.</p>
|
||||||
* Represents a list of cards with amount of each
|
* Represents a list of cards with amount of each
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
||||||
|
|
||||||
// Constructors here
|
// Constructors here
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ItemPool Constructor.
|
||||||
|
* @param cls a T
|
||||||
|
*/
|
||||||
public ItemPool(final Class<T> cls) { super(cls); }
|
public ItemPool(final Class<T> cls) { super(cls); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ItemPool Constructor.
|
||||||
|
* @param names a String
|
||||||
|
* @param cls a T
|
||||||
|
*/
|
||||||
@SuppressWarnings("unchecked") // conversion here must be safe
|
@SuppressWarnings("unchecked") // conversion here must be safe
|
||||||
public ItemPool(final Iterable<String> names, final Class<T> cls) { super(cls); addAllCards((Iterable<T>) CardDb.instance().getCards(names)); }
|
public ItemPool(final Iterable<String> names, final Class<T> cls) {
|
||||||
|
super(cls);
|
||||||
|
addAllCards((Iterable<T>) CardDb.instance().getCards(names));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* createFrom method.
|
||||||
|
* @param from a Tin
|
||||||
|
* @param clsHint a Tout
|
||||||
|
* @return InventoryItem
|
||||||
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout>
|
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout>
|
||||||
createFrom(ItemPoolView<Tin> from, Class<Tout> clsHint)
|
createFrom(final ItemPoolView<Tin> from, final Class<Tout> clsHint)
|
||||||
{
|
{
|
||||||
ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
||||||
if (from != null) {
|
if (from != null) {
|
||||||
@@ -32,9 +54,16 @@ public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* createFrom method.
|
||||||
|
* @param from a Iterable<Tin>
|
||||||
|
* @param clsHint a Class<Tout>
|
||||||
|
* @return InventoryItem
|
||||||
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout>
|
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout>
|
||||||
createFrom(Iterable<Tin> from, Class<Tout> clsHint)
|
createFrom(final Iterable<Tin> from, final Class<Tout> clsHint)
|
||||||
{
|
{
|
||||||
ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
||||||
if (from != null) {
|
if (from != null) {
|
||||||
@@ -48,26 +77,55 @@ public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get
|
// get
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Get item view.
|
||||||
|
* @return a ItemPoolView
|
||||||
|
*/
|
||||||
public ItemPoolView<T> getView() { return new ItemPoolView<T>(Collections.unmodifiableMap(cards), myClass); }
|
public ItemPoolView<T> getView() { return new ItemPoolView<T>(Collections.unmodifiableMap(cards), myClass); }
|
||||||
|
|
||||||
// Cards manipulation
|
// Cards manipulation
|
||||||
public void add(final T card) { add(card, 1); }
|
/**
|
||||||
|
*
|
||||||
|
* Add Card.
|
||||||
|
* @param card a T
|
||||||
|
*/
|
||||||
|
public void add(final T card) {
|
||||||
|
add(card, 1);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* add method.
|
||||||
|
* @param card a T
|
||||||
|
* @param amount a int
|
||||||
|
*/
|
||||||
public void add(final T card, final int amount) {
|
public void add(final T card, final int amount) {
|
||||||
if (amount <= 0) { return; }
|
if (amount <= 0) { return; }
|
||||||
cards.put(card, count(card) + amount);
|
cards.put(card, count(card) + amount);
|
||||||
isListInSync = false;
|
isListInSync = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void put(final T card, final int amount) {
|
private void put(final T card, final int amount) {
|
||||||
cards.put(card, amount);
|
cards.put(card, amount);
|
||||||
isListInSync = false;
|
isListInSync = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* addAllCards.
|
||||||
|
* @param cards a <U>
|
||||||
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <U extends InventoryItem> void addAllCards(final Iterable<U> cards) {
|
public <U extends InventoryItem> void addAllCards(final Iterable<U> cards) {
|
||||||
for (U cr : cards) { if (myClass.isInstance(cr)) { add((T) cr); } }
|
for (U cr : cards) { if (myClass.isInstance(cr)) { add((T) cr); } }
|
||||||
isListInSync = false;
|
isListInSync = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* addAll.
|
||||||
|
* @param map
|
||||||
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <U extends InventoryItem> void addAll(final Iterable<Entry<U, Integer>> map) {
|
public <U extends InventoryItem> void addAll(final Iterable<Entry<U, Integer>> map) {
|
||||||
for (Entry<U, Integer> e : map) {
|
for (Entry<U, Integer> e : map) {
|
||||||
@@ -78,7 +136,21 @@ public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
isListInSync = false;
|
isListInSync = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(final T card) { remove(card, 1); }
|
/**
|
||||||
|
*
|
||||||
|
* Remove.
|
||||||
|
* @param card a T
|
||||||
|
*/
|
||||||
|
public void remove(final T card) {
|
||||||
|
remove(card, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Remove.
|
||||||
|
* @param card a T
|
||||||
|
* @param amount a int
|
||||||
|
*/
|
||||||
public void remove(final T card, final int amount) {
|
public void remove(final T card, final int amount) {
|
||||||
int count = count(card);
|
int count = count(card);
|
||||||
if (count == 0 || amount <= 0) { return; }
|
if (count == 0 || amount <= 0) { return; }
|
||||||
@@ -86,10 +158,19 @@ public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
else { cards.put(card, count - amount); }
|
else { cards.put(card, count - amount); }
|
||||||
isListInSync = false;
|
isListInSync = false;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* RemoveAll.
|
||||||
|
* @param map a T
|
||||||
|
*/
|
||||||
public void removeAll(final Iterable<Entry<T, Integer>> map) {
|
public void removeAll(final Iterable<Entry<T, Integer>> map) {
|
||||||
for (Entry<T, Integer> e : map) { remove(e.getKey(), e.getValue()); }
|
for (Entry<T, Integer> e : map) { remove(e.getKey(), e.getValue()); }
|
||||||
isListInSync = false;
|
isListInSync = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Clear.
|
||||||
|
*/
|
||||||
public void clear() { cards.clear(); isListInSync = false; }
|
public void clear() { cards.clear(); isListInSync = false; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class QuestEventManager {
|
|||||||
|
|
||||||
DeckManager manager = new DeckManager(file);
|
DeckManager manager = new DeckManager(file);
|
||||||
|
|
||||||
File[] allFiles = ForgeProps.getFile(NewConstants.QUEST.DECKS).listFiles(DeckManager.DCKFileFilter);
|
File[] allFiles = ForgeProps.getFile(NewConstants.QUEST.DECKS).listFiles(DeckManager.DCK_FILE_FILTER);
|
||||||
|
|
||||||
for(File f : allFiles) {
|
for(File f : allFiles) {
|
||||||
contents = FileUtil.readFile(f);
|
contents = FileUtil.readFile(f);
|
||||||
|
|||||||
Reference in New Issue
Block a user