mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Removed very old quest data format handling.
This commit is contained in:
4
.gitattributes
vendored
4
.gitattributes
vendored
@@ -7150,10 +7150,6 @@ res/quest/themes/Wolves[!!-~]WG.thm -text
|
||||
res/reprintSetInfo.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
|
||||
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/arcane/ui/CardArea.java svneol=native#text/plain
|
||||
src/arcane/ui/CardPanel.java svneol=native#text/plain
|
||||
src/arcane/ui/CardPanelContainer.java svneol=native#text/plain
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
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
|
||||
@@ -1,50 +0,0 @@
|
||||
/**
|
||||
* QuestData_State.java
|
||||
*
|
||||
* Created on 26.10.2009
|
||||
*/
|
||||
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
||||
/**
|
||||
* The class QuestData_State. 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
|
||||
*/
|
||||
@SuppressWarnings({"deprecation"})
|
||||
@Deprecated
|
||||
public class QuestData_State implements Serializable {
|
||||
private static final long serialVersionUID = 7007940230351051937L;
|
||||
|
||||
int rankIndex, win, lost;
|
||||
int plantLevel, wolfPetLevel, crocPetLevel, birdPetLevel, houndPetLevel, life, estatesLevel, luckyCoinLevel, sleightOfHandLevel, gearLevel, questsPlayed;
|
||||
long credits;
|
||||
String difficulty, mode, selectedPet;
|
||||
|
||||
|
||||
ArrayList<Integer> availableQuests, completedQuests;
|
||||
ArrayList<String> cardPool, shopList;
|
||||
HashMap<String, Deck> myDecks, aiDecks;
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
// System.out.println("resolving obsolete QuestData_State");
|
||||
Map<String, forge.Deck> myDecks = new HashMap<String, forge.Deck>();
|
||||
for(Entry<String, Deck> deck:this.myDecks.entrySet()) {
|
||||
myDecks.put(deck.getKey(), deck.getValue().migrate());
|
||||
}
|
||||
|
||||
Map<String, forge.Deck> aiDecks = new HashMap<String, forge.Deck>();
|
||||
for(Entry<String, Deck> deck:this.aiDecks.entrySet()) {
|
||||
aiDecks.put(deck.getKey(), deck.getValue().migrate());
|
||||
}
|
||||
return new forge.QuestData_State(rankIndex, win, lost, plantLevel, wolfPetLevel, crocPetLevel, birdPetLevel, houndPetLevel, selectedPet, life, estatesLevel, luckyCoinLevel, sleightOfHandLevel, gearLevel, questsPlayed, availableQuests, completedQuests,credits, difficulty, mode, cardPool, shopList, myDecks, aiDecks);
|
||||
}
|
||||
}
|
||||
@@ -135,15 +135,6 @@ 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;
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
Reference in New Issue
Block a user