Restored DeckConverter

This commit is contained in:
jendave
2011-08-06 17:48:14 +00:00
parent 902623e207
commit 09798d82ab
3 changed files with 129 additions and 0 deletions

2
.gitattributes vendored
View File

@@ -7223,6 +7223,8 @@ res/quest/themes/Wolves[!!-~]WG.thm -text
res/reprintSetInfo.py -text svneol=native#text/x-python res/reprintSetInfo.py -text svneol=native#text/x-python
res/setInfoScript.py -text svneol=native#text/x-python res/setInfoScript.py -text svneol=native#text/x-python
res/sound/tap.mp3 -text svneol=unset#audio/mpeg res/sound/tap.mp3 -text svneol=unset#audio/mpeg
src/Deck.java svneol=native#text/plain
src/DeckConverter.java svneol=native#text/plain
src/arcane/ui/CardArea.java svneol=native#text/plain src/arcane/ui/CardArea.java svneol=native#text/plain
src/arcane/ui/CardPanel.java svneol=native#text/plain src/arcane/ui/CardPanel.java svneol=native#text/plain
src/arcane/ui/CardPanelContainer.java svneol=native#text/plain src/arcane/ui/CardPanelContainer.java svneol=native#text/plain

37
src/Deck.java Normal file
View File

@@ -0,0 +1,37 @@
/**
* Deck.java
*
* Created on 26.10.2009
*/
import java.io.Serializable;
import java.util.ArrayList;
/**
* The class Deck. This class is only here for compatibility with forge versions 10/17 and older. When it is read
* from the file stream, the object is replaced with an object of type {@link Deck} using {@link #readResolve()}.
*
* @author Clemens Koza
*/
public class Deck implements Serializable {
private static final long serialVersionUID = -2188987217361601903L;
private String deckType;
/*
private boolean isRegular;
private boolean isSealed;
private boolean isDraft;
*/
private ArrayList<String> main;
private ArrayList<String> sideboard;
//very important, do NOT change this
private String name;
public forge.Deck migrate() {
return new forge.Deck(deckType, main, sideboard, name);
}
}

90
src/DeckConverter.java Normal file
View File

@@ -0,0 +1,90 @@
/**
* DeckConverter.java
*
* Created on 08.11.2009
*/
import static java.lang.String.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.swing.JOptionPane;
import forge.DeckIO;
import forge.NewDeckIO;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
/**
* The class DeckConverter. This class uses an {@link OldDeckIO} and a {@link NewDeckIO} to convert the old
* all-decks2 file into the new folder structure.
*
* @version V0.0 08.11.2009
* @author Clemens Koza
*/
public class DeckConverter {
public static void main(String[] args) {
File oldDecks = ForgeProps.getFile(NewConstants.DECKS);
File newDecks = ForgeProps.getFile(NewConstants.NEW_DECKS);
if(oldDecks == null || !oldDecks.isFile()) return;
int choice = JOptionPane.showConfirmDialog(null, format(
"This dialog lets you migrate your old decks to the new version of forge.%n"
+ "Your old decks file: %s%nYour new decks directory: %s%n%n"
+ "If you don't want to see this dialog again, please remove/rename your %1$s file,%n"
+ "or otherwise hide it from forge.%n%nDo you want to migrate your decks now?", oldDecks,
newDecks), "Deck Migration", JOptionPane.YES_NO_OPTION);
if(choice != JOptionPane.YES_OPTION) return;
System.out.println("migrating deck file...");
DeckIO odio = new OldDeckIO(oldDecks);
List<forge.Deck> deckList = new ArrayList<forge.Deck>(Arrays.asList(odio.getDecks()));
Map<String, forge.Deck[]> boosterMap = odio.getBoosterDecks();
System.out.println("Decks found:");
System.out.printf("\t%d normal decks%n", deckList.size());
System.out.printf("\t%d booster decks%n", boosterMap.size());
//the constructor loads the decks from NEW_DECKS and preserves those from the collections
DeckIO ndio = new NewDeckIO(newDecks, deckList, boosterMap);
System.out.println("Decks in NewDeckIO:");
System.out.printf("\t%d normal decks%n", ndio.getDecks().length);
System.out.printf("\t%d booster decks%n", ndio.getBoosterDecks().size());
//stores all the decks (new and old) to the directory.
ndio.close();
JOptionPane.showMessageDialog(null, "Your deck file was successfully migrated!");
}
/**
*
*/
public static Object toForgeDeck(Object o) {
if(o instanceof forge.Deck) {
//a single new-type deck
return o;
} else if(o instanceof forge.Deck[]) {
//a new-type booster deck
return o;
} else if(o instanceof Deck) {
// an old type deck
Deck d = (Deck) o;
return d.migrate();
} else if(o instanceof Deck[]) {
Deck[] d = (Deck[]) o;
forge.Deck[] result = new forge.Deck[d.length];
for(int i = 0; i < d.length; i++) {
result[i] = d[i].migrate();
}
return result;
} else throw new IllegalArgumentException();
}
}