get gauntlets working, including fixing all the malformed data in the contest files

This commit is contained in:
myk
2013-03-15 03:13:33 +00:00
parent 2e5e4d1dfb
commit 173b0c9490
17 changed files with 103 additions and 170 deletions

View File

@@ -22,6 +22,8 @@ import java.util.concurrent.ExecutionException;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import org.apache.commons.lang3.StringUtils;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException; import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
@@ -93,8 +95,8 @@ public class ImageCache {
} }
private static BufferedImage scaleImage(String key, final int width, final int height) { private static BufferedImage scaleImage(String key, final int width, final int height) {
if ((3 > width && -1 != width) || (3 > height && -1 != height)) { if (StringUtils.isEmpty(key) || (3 > width && -1 != width) || (3 > height && -1 != height)) {
// picture too small; return a blank // picture too small or key not defined; return a blank
return null; return null;
} }

View File

@@ -53,18 +53,10 @@ import forge.util.FileUtil;
* The set of MTG legal cards that become player's library when the game starts. * The set of MTG legal cards that become player's library when the game starts.
* Any other data is not part of a deck and should be stored elsewhere. Current * Any other data is not part of a deck and should be stored elsewhere. Current
* fields allowed for deck metadata are Name, Title, Description and Deck Type. * fields allowed for deck metadata are Name, Title, Description and Deck Type.
*
* @author Forge
* @version $Id$
*/ */
@SuppressWarnings("serial")
public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPool>> { public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPool>> {
/**
*
*/
private static final long serialVersionUID = -7478025567887481994L;
private final Map<DeckSection, CardPool> parts = new EnumMap<DeckSection, CardPool>(DeckSection.class); private final Map<DeckSection, CardPool> parts = new EnumMap<DeckSection, CardPool>(DeckSection.class);
private final Set<String> tags = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); private final Set<String> tags = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
// gameType is from Constant.GameType, like GameType.Regular // gameType is from Constant.GameType, like GameType.Regular

View File

@@ -1,11 +1,6 @@
package forge.deck; package forge.deck;
/**
* TODO: Write javadoc for this type.
*
*/
public enum DeckSection { public enum DeckSection {
Avatar(1), Avatar(1),
Commander(1), Commander(1),
Main(60), Main(60),
@@ -24,12 +19,14 @@ public enum DeckSection {
if (value == null) { if (value == null) {
return null; return null;
} }
final String valToCompate = value.trim(); final String valToCompate = value.trim();
for (final DeckSection v : DeckSection.values()) { for (final DeckSection v : DeckSection.values()) {
if (v.name().compareToIgnoreCase(valToCompate) == 0) { if (v.name().compareToIgnoreCase(valToCompate) == 0) {
return v; return v;
} }
} }
return null; return null;
} }
} }

View File

@@ -1,12 +1,13 @@
package forge.gauntlet; package forge.gauntlet;
import java.io.File;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import forge.deck.Deck; import forge.deck.Deck;
@@ -16,8 +17,10 @@ import forge.deck.Deck;
* <br><br><i>(S at beginning of class name denotes a static factory.)</i> * <br><br><i>(S at beginning of class name denotes a static factory.)</i>
*/ */
public final class GauntletData { public final class GauntletData {
@XStreamOmitField
private String name; // set based on the the filename on load
private int completed; private int completed;
private File activeFile;
private String timestamp; private String timestamp;
private List<String> eventRecords = new ArrayList<String>(); private List<String> eventRecords = new ArrayList<String>();
private List<String> eventNames = new ArrayList<String>(); private List<String> eventNames = new ArrayList<String>();
@@ -31,17 +34,14 @@ public final class GauntletData {
//========== Mutator / accessor methods //========== Mutator / accessor methods
/** @param file0 {@link java.io.File} */ public void setName(String name0) {
public void setActiveFile(final File file0) { name = name0;
this.activeFile = file0;
} }
/** @return {@link java.io.File} */ public String getName() {
public File getActiveFile() { return name;
return this.activeFile;
} }
/** */
public void stamp() { public void stamp() {
final DateFormat dateFormat = new SimpleDateFormat("dd-mm-yy, H:m"); final DateFormat dateFormat = new SimpleDateFormat("dd-mm-yy, H:m");
this.timestamp = dateFormat.format(new Date()).toString(); this.timestamp = dateFormat.format(new Date()).toString();
@@ -61,64 +61,52 @@ public final class GauntletData {
GauntletIO.saveGauntlet(this); GauntletIO.saveGauntlet(this);
} }
/** @return {@link java.lang.String} */
public String getTimestamp() { public String getTimestamp() {
return this.timestamp; return this.timestamp;
} }
/** @param i0 int */
public void setCompleted(final int i0) { public void setCompleted(final int i0) {
this.completed = i0; this.completed = i0;
} }
/** @return int */
public int getCompleted() { public int getCompleted() {
return this.completed; return this.completed;
} }
/** @param d0 {@link forge.deck.Deck} */
public void setUserDeck(final Deck d0) { public void setUserDeck(final Deck d0) {
this.userDeck = d0; this.userDeck = d0;
} }
/** @return d0 {@link forge.deck.Deck} */
public Deck getUserDeck() { public Deck getUserDeck() {
return this.userDeck; return this.userDeck;
} }
/** @return List<String> */
public List<String> getDeckNames() { public List<String> getDeckNames() {
final List<String> names = new ArrayList<String>(); final List<String> names = new ArrayList<String>();
for (final Deck d : decks) { names.add(d.getName()); } for (final Deck d : decks) { names.add(d.getName()); }
return names; return names;
} }
/** @param records0 List<String> */
public void setEventRecords(final List<String> records0) { public void setEventRecords(final List<String> records0) {
this.eventRecords = records0; this.eventRecords = records0;
} }
/** @return List<String> */
public List<String> getEventRecords() { public List<String> getEventRecords() {
return this.eventRecords; return this.eventRecords;
} }
/** @param names0 List<String> */
public void setEventNames(final List<String> names0) { public void setEventNames(final List<String> names0) {
this.eventNames = names0; this.eventNames = names0;
} }
/** @return List<String> */
public List<String> getEventNames() { public List<String> getEventNames() {
return this.eventNames; return this.eventNames;
} }
/** @param decks0 List<Deck> */
public void setDecks(final List<Deck> decks0) { public void setDecks(final List<Deck> decks0) {
this.decks = decks0; this.decks = decks0;
} }
/** @return List<Deck> */
public List<Deck> getDecks() { public List<Deck> getDecks() {
return this.decks; return this.decks;
} }

View File

@@ -27,25 +27,16 @@ import forge.item.CardPrinted;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.util.IgnoringXStream; import forge.util.IgnoringXStream;
/** */
public class GauntletIO { public class GauntletIO {
/** Prompt in text field for new (unsaved) built gauntlets. */ /** Prompt in text field for new (unsaved) built gauntlets. */
public static final String TXF_PROMPT = "[New Gauntlet]"; public static final String TXF_PROMPT = "[New Gauntlet]";
/** suffix for all gauntlet data files */
public static final String SUFFIX_DATA = ".dat";
/** Prefix for quick gauntlet save files. */ /** Prefix for quick gauntlet save files. */
public static final String PREFIX_QUICK = "Quick_"; public static final String PREFIX_QUICK = "Quick_";
/** Regex for quick gauntlet save files. */
public static final String REGEX_QUICK = "^" + GauntletIO.PREFIX_QUICK + "[0-9]+\\.dat$";
/** Regex for locked gauntlet save files. */ /** Regex for locked gauntlet save files. */
public static final String REGEX_LOCKED = "^LOCKED_.+\\.dat$"; public static final String PREFIX_LOCKED = "LOCKED_";
/** Regex for Subversion files. */
public static final String SVN_IGNORE = "^\\.svn$";
/**
* Gets the serializer.
*
* @param isIgnoring the is ignoring
* @return the serializer
*/
protected static XStream getSerializer(final boolean isIgnoring) { protected static XStream getSerializer(final boolean isIgnoring) {
final XStream xStream = isIgnoring ? new IgnoringXStream() : new XStream(); final XStream xStream = isIgnoring ? new IgnoringXStream() : new XStream();
xStream.registerConverter(new DeckSectionToXml()); xStream.registerConverter(new DeckSectionToXml());
@@ -53,42 +44,43 @@ public class GauntletIO {
return xStream; return xStream;
} }
public static File getGauntletFile(String name) {
return new File(NewConstants.GAUNTLET_DIR.userPrefLoc, name + SUFFIX_DATA);
}
public static File getGauntletFile(GauntletData gd) {
return getGauntletFile(gd.getName());
}
/** @return File[] */
public static File[] getGauntletFilesUnlocked() { public static File[] getGauntletFilesUnlocked() {
final FilenameFilter filter = new FilenameFilter() { final FilenameFilter filter = new FilenameFilter() {
@Override @Override
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
return (!name.matches(GauntletIO.REGEX_LOCKED) return (name.endsWith(SUFFIX_DATA));
&& !name.matches(GauntletIO.SVN_IGNORE));
} }
}; };
File folder = new File(NewConstants.GAUNTLET_DIR.defaultLoc); File folder = new File(NewConstants.GAUNTLET_DIR.userPrefLoc);
return folder.listFiles(filter); return folder.listFiles(filter);
} }
/** @return File[] */
public static File[] getGauntletFilesQuick() { public static File[] getGauntletFilesQuick() {
final FilenameFilter filter = new FilenameFilter() { final FilenameFilter filter = new FilenameFilter() {
@Override @Override
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
return (name.matches(GauntletIO.REGEX_QUICK) return (name.startsWith(PREFIX_QUICK) && name.endsWith(SUFFIX_DATA));
&& !name.matches(GauntletIO.SVN_IGNORE));
} }
}; };
File folder = new File(NewConstants.GAUNTLET_DIR.defaultLoc); File folder = new File(NewConstants.GAUNTLET_DIR.userPrefLoc);
return folder.listFiles(filter); return folder.listFiles(filter);
} }
/** @return File[] */
public static File[] getGauntletFilesLocked() { public static File[] getGauntletFilesLocked() {
final FilenameFilter filter = new FilenameFilter() { final FilenameFilter filter = new FilenameFilter() {
@Override @Override
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
return (name.matches(GauntletIO.REGEX_LOCKED) return (name.startsWith(PREFIX_LOCKED) && name.endsWith(SUFFIX_DATA));
&& !name.matches(GauntletIO.SVN_IGNORE));
} }
}; };
@@ -96,50 +88,29 @@ public class GauntletIO {
return folder.listFiles(filter); return folder.listFiles(filter);
} }
/**
* <p>
* loadData.
* </p>
*
* @param xmlSaveFile
* &emsp; {@link java.io.File}
* @return {@link forge.gauntlet.GauntletData}
*/
public static GauntletData loadGauntlet(final File xmlSaveFile) { public static GauntletData loadGauntlet(final File xmlSaveFile) {
GZIPInputStream zin = null;
try { try {
GauntletData data = null; zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
InputStreamReader reader = new InputStreamReader(zin);
final GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile)); GauntletData data = (GauntletData)GauntletIO.getSerializer(true).fromXML(reader);
final StringBuilder xml = new StringBuilder(); String filename = xmlSaveFile.getName();
final char[] buf = new char[1024]; data.setName(filename.substring(0, filename.length() - SUFFIX_DATA.length()));
final InputStreamReader reader = new InputStreamReader(zin);
while (reader.ready()) {
final int len = reader.read(buf);
if (len == -1) {
break;
} // when end of stream was reached
xml.append(buf, 0, len);
}
zin.close();
data = (GauntletData) GauntletIO.getSerializer(true).fromXML(xml.toString());
return data; return data;
} catch (final Exception ex) { } catch (final Exception ex) {
BugReporter.reportException(ex, "Error loading Gauntlet Data"); BugReporter.reportException(ex, "Error loading Gauntlet Data");
throw new RuntimeException(ex); throw new RuntimeException(ex);
} finally {
if (null != zin) {
try { zin.close(); }
catch (IOException e) { System.out.println("error closing gauntlet data reader: " + e); }
}
} }
} }
/**
* <p>
* saveData.
* </p>
*
* @param gd0
* a {@link forge.gauntlet.GauntletData} object.
*/
public static void saveGauntlet(final GauntletData gd0) { public static void saveGauntlet(final GauntletData gd0) {
try { try {
final XStream xStream = GauntletIO.getSerializer(false); final XStream xStream = GauntletIO.getSerializer(false);
@@ -151,7 +122,7 @@ public class GauntletIO {
} }
private static void savePacked(final XStream xStream0, final GauntletData gd0) throws IOException { private static void savePacked(final XStream xStream0, final GauntletData gd0) throws IOException {
final BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(gd0.getActiveFile())); final BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(getGauntletFile(gd0)));
final GZIPOutputStream zout = new GZIPOutputStream(bout); final GZIPOutputStream zout = new GZIPOutputStream(bout);
xStream0.toXML(gd0, zout); xStream0.toXML(gd0, zout);
zout.flush(); zout.flush();
@@ -159,7 +130,6 @@ public class GauntletIO {
} }
private static class DeckSectionToXml implements Converter { private static class DeckSectionToXml implements Converter {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Override @Override
public boolean canConvert(final Class clasz) { public boolean canConvert(final Class clasz) {
@@ -171,7 +141,6 @@ public class GauntletIO {
for (final Entry<CardPrinted, Integer> e : (CardPool) source) { for (final Entry<CardPrinted, Integer> e : (CardPool) source) {
this.writeCardPrinted(e.getKey(), e.getValue(), writer); this.writeCardPrinted(e.getKey(), e.getValue(), writer);
} }
} }
@Override @Override
@@ -190,10 +159,10 @@ public class GauntletIO {
} }
reader.moveUp(); reader.moveUp();
} }
return result; return result;
} }
/** */
private void writeCardPrinted(final CardPrinted cref, final Integer count, final HierarchicalStreamWriter writer) { private void writeCardPrinted(final CardPrinted cref, final Integer count, final HierarchicalStreamWriter writer) {
writer.startNode("card"); writer.startNode("card");
writer.addAttribute("c", cref.getName()); writer.addAttribute("c", cref.getName());

View File

@@ -832,21 +832,21 @@ public class DialogMigrateProfile {
opLogBuf.append(destFile.getAbsolutePath()).append("\n"); opLogBuf.append(destFile.getAbsolutePath()).append("\n");
if (!destFile.exists()) { if (!destFile.exists()) {
_copyFile(srcFile, destFile); _copyFile(srcFile, destFile, _move);
} else { } else {
if (_overwrite) { if (_overwrite) {
opLogBuf.append(" Destination file exists; overwriting\n"); opLogBuf.append(" Destination file exists; overwriting\n");
_copyFile(srcFile, destFile); _copyFile(srcFile, destFile, _move);
} else { } else {
opLogBuf.append(" Destination file exists; skipping copy\n"); opLogBuf.append(" Destination file exists; skipping copy\n");
} }
++numExisting; ++numExisting;
} }
if (_move) { if (_move) {
opLogBuf.append(" Removing source file after successful copy\n"); // source file may have been deleted already if _copyFile was called
srcFile.delete(); srcFile.delete();
opLogBuf.append(" Removed source file after successful copy\n");
} }
++numSucceeded; ++numSucceeded;
@@ -896,10 +896,17 @@ public class DialogMigrateProfile {
} }
} }
// actual file copy routine. uses java.nio classes for ultra-fast copying // when copying is required, uses java nio classes for ultra-fast I/O
private static void _copyFile(File srcFile, File destFile) throws IOException { private static void _copyFile(File srcFile, File destFile, boolean deleteSrcAfter) throws IOException {
destFile.getParentFile().mkdirs(); destFile.getParentFile().mkdirs();
// if this is a move, try a simple rename first
if (deleteSrcAfter) {
if (srcFile.renameTo(destFile)) {
return;
}
}
if (!destFile.exists()) { if (!destFile.exists()) {
destFile.createNewFile(); destFile.createNewFile();
} }
@@ -914,5 +921,9 @@ public class DialogMigrateProfile {
if (src != null) { src.close(); } if (src != null) { src.close(); }
if (dest != null) { dest.close(); } if (dest != null) { dest.close(); }
} }
if (deleteSrcAfter) {
srcFile.delete();
}
} }
} }

View File

@@ -42,13 +42,11 @@ import forge.util.storage.IStorage;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public enum CSubmenuGauntletBuild implements ICDoc { public enum CSubmenuGauntletBuild implements ICDoc {
/** */
SINGLETON_INSTANCE; SINGLETON_INSTANCE;
private final VSubmenuGauntletBuild view = VSubmenuGauntletBuild.SINGLETON_INSTANCE; private final VSubmenuGauntletBuild view = VSubmenuGauntletBuild.SINGLETON_INSTANCE;
private final List<Deck> workingDecks = new ArrayList<Deck>(); private final List<Deck> workingDecks = new ArrayList<Deck>();
private File previousDirectory = null; private File openStartDir = new File(NewConstants.GAUNTLET_DIR.userPrefLoc);
private File openStartDir = new File(NewConstants.GAUNTLET_DIR.defaultLoc);
private final FileFilter filterDAT = new FileFilter() { private final FileFilter filterDAT = new FileFilter() {
@Override @Override
@@ -57,12 +55,8 @@ public enum CSubmenuGauntletBuild implements ICDoc {
return true; return true;
} }
if (!f.getName().matches(GauntletIO.REGEX_LOCKED) String filename = f.getName();
&& !f.getName().matches(GauntletIO.REGEX_QUICK)) { return (!filename.startsWith(GauntletIO.PREFIX_QUICK) && filename.endsWith(GauntletIO.SUFFIX_DATA));
return true;
}
return false;
} }
@Override @Override
@@ -318,7 +312,7 @@ public enum CSubmenuGauntletBuild implements ICDoc {
return false; return false;
} }
final File f = new File(NewConstants.GAUNTLET_DIR.defaultLoc + name + ".dat"); final File f = new File(NewConstants.GAUNTLET_DIR.userPrefLoc + name + ".dat");
// Confirm if overwrite // Confirm if overwrite
if (f.exists()) { if (f.exists()) {
final int m = JOptionPane.showConfirmDialog(null, final int m = JOptionPane.showConfirmDialog(null,
@@ -350,7 +344,7 @@ public enum CSubmenuGauntletBuild implements ICDoc {
gd.setEventNames(names); gd.setEventNames(names);
gd.setDecks(workingDecks); gd.setDecks(workingDecks);
gd.setActiveFile(f); gd.setName(name);
gd.reset(); gd.reset();
view.getLblSave().setVisible(false); view.getLblSave().setVisible(false);
@@ -359,17 +353,14 @@ public enum CSubmenuGauntletBuild implements ICDoc {
} }
private boolean openGauntlet() { private boolean openGauntlet() {
/** */
final File file; final File file;
final JFileChooser open = new JFileChooser(previousDirectory); final JFileChooser open = new JFileChooser(openStartDir);
open.setDialogTitle("Import Deck"); open.setDialogTitle("Import Deck");
open.addChoosableFileFilter(this.filterDAT); open.addChoosableFileFilter(this.filterDAT);
open.setCurrentDirectory(openStartDir);
final int returnVal = open.showOpenDialog(null); final int returnVal = open.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION) {
file = open.getSelectedFile(); file = open.getSelectedFile();
previousDirectory = file.getParentFile();
} }
else { else {
return false; return false;

View File

@@ -140,12 +140,9 @@ public enum CSubmenuGauntletContests implements ICDoc {
private void updateData() { private void updateData() {
final File[] files = GauntletIO.getGauntletFilesLocked(); final File[] files = GauntletIO.getGauntletFilesLocked();
final List<GauntletData> data = new ArrayList<GauntletData>(); final List<GauntletData> data = new ArrayList<GauntletData>();
for (final File f : files) { for (final File f : files) {
if (f.getName().matches(GauntletIO.REGEX_LOCKED)) {
data.add(GauntletIO.loadGauntlet(f)); data.add(GauntletIO.loadGauntlet(f));
} }
}
view.getGauntletLister().setGauntlets(data); view.getGauntletLister().setGauntlets(data);
view.getGauntletLister().setSelectedIndex(0); view.getGauntletLister().setSelectedIndex(0);

View File

@@ -31,12 +31,9 @@ import forge.model.FModel;
* <br><br><i>(C at beginning of class name denotes a control class.)</i> * <br><br><i>(C at beginning of class name denotes a control class.)</i>
* *
*/ */
public enum CSubmenuGauntletLoad implements ICDoc { public enum CSubmenuGauntletLoad implements ICDoc {
/** */
SINGLETON_INSTANCE; SINGLETON_INSTANCE;
private final ActionListener actStartGame = new ActionListener() { @Override private final ActionListener actStartGame = new ActionListener() { @Override
public void actionPerformed(ActionEvent arg0) { startGame(); } }; public void actionPerformed(ActionEvent arg0) { startGame(); } };
@@ -47,6 +44,11 @@ public enum CSubmenuGauntletLoad implements ICDoc {
*/ */
@Override @Override
public void update() { public void update() {
updateData();
enableStartButton();
view.getGauntletLister().setSelectedIndex(0);
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override public void run() { @Override public void run() {
JButton btnStart = view.getBtnStart(); JButton btnStart = view.getBtnStart();
@@ -67,10 +69,6 @@ public enum CSubmenuGauntletLoad implements ICDoc {
public void initialize() { public void initialize() {
view.getBtnStart().addActionListener(actStartGame); view.getBtnStart().addActionListener(actStartGame);
updateData();
enableStartButton();
view.getGauntletLister().setSelectedIndex(0);
view.getGauntletLister().setCmdDelete(new Command() { @Override view.getGauntletLister().setCmdDelete(new Command() { @Override
public void execute() { enableStartButton(); } }); public void execute() { enableStartButton(); } });
view.getGauntletLister().setCmdSelect(new Command() { @Override view.getGauntletLister().setCmdSelect(new Command() { @Override
@@ -89,7 +87,7 @@ public enum CSubmenuGauntletLoad implements ICDoc {
} }
private void enableStartButton() { private void enableStartButton() {
if (view.getGauntletLister().getSelectedGauntlet() == null) { if (view.getGauntletLister().getSelectedGauntletFile() == null) {
view.getBtnStart().setEnabled(false); view.getBtnStart().setEnabled(false);
} }
else { else {
@@ -99,8 +97,7 @@ public enum CSubmenuGauntletLoad implements ICDoc {
private void startGame() { private void startGame() {
FModel.SINGLETON_INSTANCE.setGauntletData( FModel.SINGLETON_INSTANCE.setGauntletData(
GauntletIO.loadGauntlet(VSubmenuGauntletQuick.SINGLETON_INSTANCE GauntletIO.loadGauntlet(VSubmenuGauntletQuick.SINGLETON_INSTANCE.getGauntletLister().getSelectedGauntletFile()));
.getGauntletLister().getSelectedGauntlet().getActiveFile()));
// Start game // Start game
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {

View File

@@ -7,7 +7,9 @@ import java.awt.event.MouseEvent;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
@@ -32,7 +34,6 @@ import forge.gauntlet.GauntletIO;
import forge.gui.SOverlayUtils; import forge.gui.SOverlayUtils;
import forge.gui.framework.ICDoc; import forge.gui.framework.ICDoc;
import forge.model.FModel; import forge.model.FModel;
import forge.properties.NewConstants;
import forge.quest.QuestController; import forge.quest.QuestController;
import forge.quest.QuestEvent; import forge.quest.QuestEvent;
import forge.util.storage.IStorage; import forge.util.storage.IStorage;
@@ -206,7 +207,6 @@ public enum CSubmenuGauntletQuick implements ICDoc {
view.getLstDecks().setSelectedIndices(new int[]{0, 1}); view.getLstDecks().setSelectedIndices(new int[]{0, 1});
} }
/** */
private void startGame() { private void startGame() {
// Start game overlay // Start game overlay
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@@ -219,13 +219,12 @@ public enum CSubmenuGauntletQuick implements ICDoc {
// Find appropriate filename for new save, create and set new save file. // Find appropriate filename for new save, create and set new save file.
final File[] arrFiles = GauntletIO.getGauntletFilesQuick(); final File[] arrFiles = GauntletIO.getGauntletFilesQuick();
final List<String> lstNames = new ArrayList<String>(); final Set<String> setNames = new HashSet<String>();
for (File f : arrFiles) { lstNames.add(f.getName()); } for (File f : arrFiles) { setNames.add(f.getName()); }
int num = 1; int num = 1;
while (lstNames.contains(GauntletIO.PREFIX_QUICK + num + ".dat")) { num++; } while (setNames.contains(GauntletIO.PREFIX_QUICK + num + GauntletIO.SUFFIX_DATA)) { num++; }
FModel.SINGLETON_INSTANCE.getGauntletData().setActiveFile(new File( FModel.SINGLETON_INSTANCE.getGauntletData().setName(GauntletIO.PREFIX_QUICK + num);
NewConstants.GAUNTLET_DIR.defaultLoc + GauntletIO.PREFIX_QUICK + num + ".dat"));
// Pull user deck // Pull user deck
final Deck userDeck; final Deck userDeck;

View File

@@ -17,6 +17,7 @@ import javax.swing.border.MatteBorder;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import forge.Command; import forge.Command;
import forge.gauntlet.GauntletData; import forge.gauntlet.GauntletData;
import forge.gauntlet.GauntletIO;
import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FLabel;
import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin;
@@ -52,7 +53,7 @@ public class ContestGauntletLister extends JPanel {
Collections.sort(sorted, new Comparator<GauntletData>() { Collections.sort(sorted, new Comparator<GauntletData>() {
@Override @Override
public int compare(final GauntletData x, final GauntletData y) { public int compare(final GauntletData x, final GauntletData y) {
return x.getActiveFile().getName().compareTo(y.getActiveFile().getName()); return x.getName().compareTo(y.getName());
} }
}); });
@@ -78,8 +79,8 @@ public class ContestGauntletLister extends JPanel {
String name; String name;
String progress; String progress;
for (GauntletData gd : sorted) { for (GauntletData gd : sorted) {
name = gd.getActiveFile().getName(); name = gd.getName();
name = name.substring(7, name.length() - 4); name = name.substring(GauntletIO.PREFIX_LOCKED.length());
progress = String.valueOf(Math.round( progress = String.valueOf(Math.round(
((double) gd.getCompleted() / (double) gd.getDecks().size()) * 100)) + " %"; ((double) gd.getCompleted() / (double) gd.getDecks().size()) * 100)) + " %";

View File

@@ -5,6 +5,7 @@ package forge.gui.home.gauntlet;
import java.awt.Color; import java.awt.Color;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@@ -20,6 +21,7 @@ import javax.swing.border.MatteBorder;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import forge.Command; import forge.Command;
import forge.gauntlet.GauntletData; import forge.gauntlet.GauntletData;
import forge.gauntlet.GauntletIO;
import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FLabel;
import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin;
@@ -60,7 +62,7 @@ public class QuickGauntletLister extends JPanel {
Collections.sort(sorted, new Comparator<GauntletData>() { Collections.sort(sorted, new Comparator<GauntletData>() {
@Override @Override
public int compare(final GauntletData x, final GauntletData y) { public int compare(final GauntletData x, final GauntletData y) {
return x.getActiveFile().getName().compareTo(y.getActiveFile().getName()); return x.getName().compareTo(y.getName());
} }
}); });
@@ -85,8 +87,7 @@ public class QuickGauntletLister extends JPanel {
RowPanel row; RowPanel row;
String name; String name;
for (GauntletData gd : sorted) { for (GauntletData gd : sorted) {
name = gd.getActiveFile().getName(); name = gd.getName();
name = name.substring(0, name.length() - 4);
row = new RowPanel(gd); row = new RowPanel(gd);
row.setToolTipText(name); row.setToolTipText(name);
@@ -113,12 +114,12 @@ public class QuickGauntletLister extends JPanel {
} }
/** @return {@link forge.deck.Deck} */ /** @return {@link forge.deck.Deck} */
public GauntletData getSelectedGauntlet() { public File getSelectedGauntletFile() {
if (previousSelect == null) { if (previousSelect == null) {
return null; return null;
} }
else { else {
return previousSelect.getGauntletData(); return GauntletIO.getGauntletFile(previousSelect.getGauntletData());
} }
} }
@@ -221,7 +222,7 @@ public class QuickGauntletLister extends JPanel {
*/ */
public boolean setSelectedIndex(int i0) { public boolean setSelectedIndex(int i0) {
if (i0 >= rows.length) { return false; } if (i0 >= rows.length) { return false; }
selectHandler(rows[i0]); selectHandler(rows[Math.max(0, i0)]);
return true; return true;
} }
@@ -263,7 +264,7 @@ public class QuickGauntletLister extends JPanel {
final GauntletData gd = r0.getGauntletData(); final GauntletData gd = r0.getGauntletData();
final int n = JOptionPane.showConfirmDialog(null, final int n = JOptionPane.showConfirmDialog(null,
"Are you sure you want to delete \"" + gd.getActiveFile().getName() "Are you sure you want to delete \"" + gd.getName()
+ "\" ?", "Delete Gauntlet", JOptionPane.YES_NO_OPTION); + "\" ?", "Delete Gauntlet", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.NO_OPTION) { if (n == JOptionPane.NO_OPTION) {
@@ -271,7 +272,7 @@ public class QuickGauntletLister extends JPanel {
} }
gd.getActiveFile().delete(); GauntletIO.getGauntletFile(gd).delete();
if (cmdRowDelete != null) { cmdRowDelete.execute(); } if (cmdRowDelete != null) { cmdRowDelete.execute(); }
this.setSelectedIndex(0); this.setSelectedIndex(0);

View File

@@ -102,18 +102,7 @@ public enum CSubmenuQuestData implements ICDoc {
final File dirQuests = new File(NewConstants.QUEST_SAVE_DIR); final File dirQuests = new File(NewConstants.QUEST_SAVE_DIR);
final QuestController qc = Singletons.getModel().getQuest(); final QuestController qc = Singletons.getModel().getQuest();
// Temporary transition code between v1.2.2 and v1.2.3. // Iterate over files and load quest data for each.
// Can be safely deleted after release of 1.2.3.
if (!dirQuests.exists()) {
dirQuests.mkdirs();
}
File olddata = new File("res/quest/questData.dat");
File newpath = new File(dirQuests.getPath() + "/questData.dat");
if (olddata.exists()) { olddata.renameTo(newpath); }
// end block which can be deleted
// Iterate over files and load quest datas for each.
FilenameFilter takeDatFiles = new FilenameFilter() { FilenameFilter takeDatFiles = new FilenameFilter() {
@Override @Override
public boolean accept(final File dir, final String name) { public boolean accept(final File dir, final String name) {
@@ -126,7 +115,7 @@ public enum CSubmenuQuestData implements ICDoc {
arrQuests.put(f.getName(), QuestDataIO.loadData(f)); arrQuests.put(f.getName(), QuestDataIO.loadData(f));
} }
// Populate list with available quest datas. // Populate list with available quest data.
view.getLstQuests().setQuests(new ArrayList<QuestData>(arrQuests.values())); view.getLstQuests().setQuests(new ArrayList<QuestData>(arrQuests.values()));
// If there are quests available, force select. // If there are quests available, force select.

View File

@@ -102,8 +102,8 @@ public class GauntletWinLose extends ControlWinLose {
this.getView().getBtnQuit().setText("OK"); this.getView().getBtnQuit().setText("OK");
// Remove save file if it's a quickie, or just reset it. // Remove save file if it's a quickie, or just reset it.
if (gd.getActiveFile().getName().matches(GauntletIO.REGEX_QUICK)) { if (gd.getName().startsWith(GauntletIO.PREFIX_QUICK)) {
gd.getActiveFile().delete(); GauntletIO.getGauntletFile(gd).delete();
} }
else { else {
gd.reset(); gd.reset();
@@ -131,8 +131,8 @@ public class GauntletWinLose extends ControlWinLose {
this.getView().getBtnContinue().setVisible(false); this.getView().getBtnContinue().setVisible(false);
// Remove save file if it's a quickie, or just reset it. // Remove save file if it's a quickie, or just reset it.
if (gd.getActiveFile().getName().matches(GauntletIO.REGEX_QUICK)) { if (gd.getName().startsWith(GauntletIO.PREFIX_QUICK)) {
gd.getActiveFile().delete(); GauntletIO.getGauntletFile(gd).delete();
} }
else { else {
gd.reset(); gd.reset();

View File

@@ -534,10 +534,9 @@ public class QuestDataIO {
} }
reader.moveUp(); reader.moveUp();
} }
return result; return result;
} }
} }
private static class ItemPoolToXml implements Converter { private static class ItemPoolToXml implements Converter {