mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
finally got the deck migration running - when you start forge, if there's a all-decks2 file, you're asked if you want to import it. this version has all the decks already imported, and the all-decks2 property commented out, so you're not asked again.
This commit is contained in:
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -32,6 +32,8 @@ res/rare.txt -text svneol=native#text/plain
|
||||
res/tokens.txt -text svneol=native#text/plain
|
||||
res/uncommon.txt -text svneol=native#text/plain
|
||||
src/Deck.java svneol=native#text/plain
|
||||
src/DeckConverter.java svneol=native#text/plain
|
||||
src/OldDeckIO.java svneol=native#text/plain
|
||||
src/QuestData_State.java svneol=native#text/plain
|
||||
src/forge/Ability.java svneol=native#text/plain
|
||||
src/forge/Ability_Activated.java svneol=native#text/plain
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
program/mail=mtgrares@yahoo.com
|
||||
program/forum=http://www.slightlymagic.net/forum/viewforum.php?f=26
|
||||
program/version=MTG Forge 09/11/02
|
||||
program/version=MTG Forge -- official beta: 09/11/02, SVN revision: 61
|
||||
|
||||
tokens--file=AllTokens.txt
|
||||
|
||||
decks--file=all-decks2
|
||||
#decks--file=all-decks2
|
||||
booster-decks--file=booster-decks
|
||||
decks-dir--file=decks
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
67
src/DeckConverter.java
Normal file
67
src/DeckConverter.java
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 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.Deck;
|
||||
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<Deck> deckList = new ArrayList<Deck>(Arrays.asList(odio.getDecks()));
|
||||
Map<String, 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!");
|
||||
}
|
||||
}
|
||||
176
src/OldDeckIO.java
Executable file
176
src/OldDeckIO.java
Executable file
@@ -0,0 +1,176 @@
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.DeckIO;
|
||||
import forge.error.ErrorViewer;
|
||||
|
||||
|
||||
//reads and write Deck objects
|
||||
public class OldDeckIO implements DeckIO {
|
||||
private final File file;
|
||||
private ArrayList<forge.Deck> deckList = new ArrayList<forge.Deck>();
|
||||
|
||||
//key is String of the humans deck
|
||||
//data is Deck[] size of 8
|
||||
//humans deck is Deck[0]
|
||||
private Map<String, forge.Deck[]> boosterMap = new HashMap<String, forge.Deck[]>();
|
||||
|
||||
public OldDeckIO(String filename) {
|
||||
this(new File(filename));
|
||||
}
|
||||
|
||||
public OldDeckIO(File file) {
|
||||
this.file = file;
|
||||
|
||||
readFile();
|
||||
}
|
||||
|
||||
public boolean isUnique(String deckName) {
|
||||
forge.Deck d;
|
||||
for(int i = 0; i < deckList.size(); i++) {
|
||||
d = deckList.get(i);
|
||||
if(d.getName().equals(deckName)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isUniqueDraft(String deckName) {
|
||||
ArrayList<String> key = new ArrayList<String>(boosterMap.keySet());
|
||||
|
||||
for(int i = 0; i < key.size(); i++) {
|
||||
if(key.get(i).equals(deckName)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasName(String deckName) {
|
||||
ArrayList<String> string = new ArrayList<String>();
|
||||
|
||||
for(int i = 0; i < deckList.size(); i++)
|
||||
string.add(deckList.get(i).toString());
|
||||
|
||||
Iterator<String> it = boosterMap.keySet().iterator();
|
||||
while(it.hasNext())
|
||||
string.add(it.next().toString());
|
||||
|
||||
return string.contains(deckName);
|
||||
}
|
||||
|
||||
public forge.Deck readDeck(String deckName) {
|
||||
return deckList.get(findDeckIndex(deckName));
|
||||
}
|
||||
|
||||
private int findDeckIndex(String deckName) {
|
||||
int n = -1;
|
||||
for(int i = 0; i < deckList.size(); i++)
|
||||
if((deckList.get(i)).getName().equals(deckName)) n = i;
|
||||
|
||||
if(n == -1) throw new RuntimeException("DeckIO : findDeckIndex() error, deck name not found - " + deckName);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
public void writeDeck(forge.Deck deck) {
|
||||
if(deck.getDeckType().equals(Constant.GameType.Draft)) throw new RuntimeException(
|
||||
"DeckIO : writeDeck() error, deck type is Draft");
|
||||
|
||||
deckList.add(deck);
|
||||
}
|
||||
|
||||
public void deleteDeck(String deckName) {
|
||||
deckList.remove(findDeckIndex(deckName));
|
||||
}
|
||||
|
||||
public forge.Deck[] readBoosterDeck(String deckName) {
|
||||
if(!boosterMap.containsKey(deckName)) throw new RuntimeException(
|
||||
"DeckIO : readBoosterDeck() error, deck name not found - " + deckName);
|
||||
|
||||
return boosterMap.get(deckName);
|
||||
}
|
||||
|
||||
public void writeBoosterDeck(forge.Deck[] deck) {
|
||||
checkBoosterDeck(deck);
|
||||
|
||||
boosterMap.put(deck[0].toString(), deck);
|
||||
}//writeBoosterDeck()
|
||||
|
||||
public void deleteBoosterDeck(String deckName) {
|
||||
if(!boosterMap.containsKey(deckName)) throw new RuntimeException(
|
||||
"DeckIO : deleteBoosterDeck() error, deck name not found - " + deckName);
|
||||
|
||||
boosterMap.remove(deckName);
|
||||
}
|
||||
|
||||
private void checkBoosterDeck(forge.Deck[] deck) {
|
||||
if(deck == null || deck.length != 8 || deck[0].getName().equals("")
|
||||
|| (!deck[0].getDeckType().equals(Constant.GameType.Draft))) {
|
||||
throw new RuntimeException("DeckIO : checkBoosterDeck() error, invalid deck");
|
||||
}
|
||||
// for(int i = 0; i < deck.length; i++)
|
||||
// if(deck[i].getName().equals(""))
|
||||
// throw new RuntimeException("DeckIO : checkBoosterDeck() error, deck does not have name - " +deck[i].getName());
|
||||
}//checkBoosterDeck()
|
||||
|
||||
|
||||
public forge.Deck[] getDecks() {
|
||||
forge.Deck[] out = new forge.Deck[deckList.size()];
|
||||
deckList.toArray(out);
|
||||
return out;
|
||||
}
|
||||
|
||||
public Map<String, forge.Deck[]> getBoosterDecks() {
|
||||
return new HashMap<String, forge.Deck[]>(boosterMap);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
writeFile();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void readFile() {
|
||||
try {
|
||||
//~
|
||||
// Shouldn't ever get here, but just in case...
|
||||
if(file == null) {
|
||||
return;
|
||||
}
|
||||
//~
|
||||
if(!file.exists()) return;
|
||||
|
||||
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
|
||||
|
||||
List<Deck> deckList = (List<Deck>) in.readObject();
|
||||
Map<String, Deck[]> boosterMap = (Map<String, Deck[]>) in.readObject();
|
||||
|
||||
this.deckList = new ArrayList<forge.Deck>();
|
||||
for(Deck deck:deckList) {
|
||||
this.deckList.add(deck.migrate());
|
||||
}
|
||||
this.boosterMap = new HashMap<String, forge.Deck[]>();
|
||||
for(Entry<String, Deck[]> deck:boosterMap.entrySet()) {
|
||||
Deck[] oldValue = deck.getValue();
|
||||
forge.Deck[] newValue = new forge.Deck[oldValue.length];
|
||||
for(int i = 0; i < oldValue.length; i++)
|
||||
newValue[i] = oldValue[i].migrate();
|
||||
this.boosterMap.put(deck.getKey(), newValue);
|
||||
}
|
||||
|
||||
in.close();
|
||||
} catch(Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("DeckIO : read() error, " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeFile() {
|
||||
//noop
|
||||
}
|
||||
}//DeckIO
|
||||
@@ -21,17 +21,23 @@ public class Deck implements java.io.Serializable {
|
||||
public Deck(String gameType) {
|
||||
setDeckType(gameType);
|
||||
name = "";
|
||||
|
||||
main = new ArrayList<String>();
|
||||
sideboard = new ArrayList<String>();
|
||||
mainView = unmodifiableList(main);
|
||||
|
||||
sideboard = new ArrayList<String>();
|
||||
sideboardView = unmodifiableList(sideboard);
|
||||
}
|
||||
|
||||
public Deck(String deckType, List<String> main, List<String> sideboard, String name) {
|
||||
this.deckType = deckType;
|
||||
this.main = main;
|
||||
this.sideboard = main;
|
||||
this.name = name;
|
||||
|
||||
this.main = main;
|
||||
mainView = unmodifiableList(main);
|
||||
|
||||
this.sideboard = main;
|
||||
sideboardView = unmodifiableList(sideboard);
|
||||
}
|
||||
|
||||
public List<String> getMain() {
|
||||
|
||||
@@ -115,7 +115,15 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
|
||||
|
||||
try {
|
||||
|
||||
//deck migration - this is a little hard to read, because i can't just plainly reference a class in the
|
||||
//default package
|
||||
Class<?> deckConverterClass = Class.forName("DeckConverter");
|
||||
//invoke public static void main(String[] args) of DeckConverter
|
||||
deckConverterClass.getDeclaredMethod("main", String[].class).invoke(null, (Object) null);
|
||||
} catch(Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
try {
|
||||
Constant.Runtime.GameType[0] = Constant.GameType.Constructed;
|
||||
AllZone.Computer = new ComputerAI_Input(new ComputerAI_General());
|
||||
|
||||
|
||||
@@ -56,8 +56,8 @@ public class NewDeckIO implements DeckIO {
|
||||
} else {
|
||||
dir.mkdirs();
|
||||
if(!dir.isDirectory()) throw new IOException("Directory can't be created");
|
||||
deckList = new ArrayList<Deck>();
|
||||
boosterMap = new HashMap<String, Deck[]>();
|
||||
this.deckList = new ArrayList<Deck>();
|
||||
this.boosterMap = new HashMap<String, Deck[]>();
|
||||
readFile();
|
||||
}
|
||||
} catch(IOException ex) {
|
||||
@@ -66,6 +66,12 @@ public class NewDeckIO implements DeckIO {
|
||||
}
|
||||
}
|
||||
|
||||
public NewDeckIO(File dir, List<Deck> deckList, Map<String, Deck[]> boosterMap) {
|
||||
this(dir);
|
||||
this.deckList.addAll(deckList);
|
||||
this.boosterMap.putAll(boosterMap);
|
||||
}
|
||||
|
||||
public boolean isUnique(String deckName) {
|
||||
Deck d;
|
||||
for(int i = 0; i < deckList.size(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user