new deck format working now!

decks are in the res/decks folder, every deck is a file, booster decks are directories with 8 deck files in them. currently, if you run the new version, the decks folder is created automatically, but old decks are neither migrated nor overwritten. i'll commit an import program soon

major changes include
-Deck doesn't store the three boolean fields any more, but computes them
-DeckIO is now an interface, with OldDeckIO and NewDeckIO as its implementations. OldDeckIO will probably still be used for the deck migration tool.
This commit is contained in:
jendave
2011-08-06 02:44:55 +00:00
parent 3757bf5fe9
commit 8bd5c4a2c4
19 changed files with 798 additions and 438 deletions

3
.gitattributes vendored
View File

@@ -161,8 +161,10 @@ src/forge/MyButton.java svneol=native#text/plain
src/forge/MyObservable.java svneol=native#text/plain
src/forge/MyRandom.java svneol=native#text/plain
src/forge/NameChanger.java svneol=native#text/plain
src/forge/NewDeckIO.java svneol=native#text/plain
src/forge/NewIO.java svneol=native#text/plain
src/forge/NonScrollingJEditorPane.java -text svneol=native#text/plain
src/forge/OldDeckIO.java svneol=native#text/plain
src/forge/Phase.java svneol=native#text/plain
src/forge/PhaseObserver.java svneol=native#text/plain
src/forge/PicturePanel.java svneol=native#text/plain
@@ -198,7 +200,6 @@ src/forge/Time.java svneol=native#text/plain
src/forge/UndoCommand.java svneol=native#text/plain
src/forge/Wait.java svneol=native#text/plain
src/forge/WinLose.java svneol=native#text/plain
src/forge/_ObjectInputStream.java svneol=native#text/plain
src/forge/error/ErrorViewer.java svneol=native#text/plain
src/forge/error/ExceptionHandler.java -text svneol=native#text/plain
src/forge/gui/ForgeAction.java svneol=native#text/plain

Binary file not shown.

View File

@@ -5,6 +5,7 @@ tokens--file=AllTokens.txt
decks--file=all-decks2
booster-decks--file=booster-decks
decks-dir--file=decks
card-pictures--file=card-pictures.txt
cards--file=cards.txt

View File

@@ -1,4 +1,3 @@
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.ArrayList;
@@ -25,20 +24,13 @@ public class Deck implements Serializable {
private boolean isSealed;
private boolean isDraft;
private ArrayList<String> main = new ArrayList<String>();
private ArrayList<String> sideboard = new ArrayList<String>();
private ArrayList<String> main;
private ArrayList<String> sideboard;
//very important, do NOT change this
private String name = "";
private String name;
private Object readResolve() throws ObjectStreamException {
System.out.println("resolving obsolete Deck");
forge.Deck d = new forge.Deck(deckType);
d.setName(name);
for(String s:main)
d.addMain(s);
for(String s:sideboard)
d.addSideboard(s);
return d;
public forge.Deck migrate() {
return new forge.Deck(deckType, main, sideboard, name);
}
}

View File

@@ -28,7 +28,7 @@ public class QuestData_State implements Serializable {
@SuppressWarnings("unchecked")
private Object readResolve() throws ObjectStreamException {
System.out.println("resolving obsolete QuestData_State");
// System.out.println("resolving obsolete QuestData_State");
//removing generic types to make cast between Deck and forge.Deck
//i'm using Deck in this class because it may be somewhere in the serialization stream
//it is irrelevant, because readResolve replaces Deck by forge.Deck, and since generics

View File

@@ -1,118 +1,124 @@
package forge;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.swing.ImageIcon;
public interface Constant
{
public static final String ProgramName = "MTG Forge - 10/2009 - http://mtgrares.blogspot.com";
//used to pass information between the GUI screens
public interface Runtime
{
public static final Deck[] HumanDeck = new Deck[1];
public static final Deck[] ComputerDeck = new Deck[1];
public static final String[] GameType = new String[1];
public static final WinLose WinLose = new WinLose();
public static final boolean[] smooth = new boolean[1];
public interface Constant {
public static final String ProgramName = "MTG Forge - 10/2009 - http://mtgrares.blogspot.com";
public static final int[] width = new int[1];
public static final int[] height = new int[1];
//used to pass information between the GUI screens
public interface Runtime {
public static final Deck[] HumanDeck = new Deck[1];
public static final Deck[] ComputerDeck = new Deck[1];
public static final String[] GameType = new String[1];
public static final WinLose WinLose = new WinLose();
public static final boolean[] smooth = new boolean[1];
}
public interface GameType
{
public static final String Constructed = "constructed";
public static final String Sealed = "sealed";
public static final String Draft = "draft";
}
public interface IO
{
//TODO: probably should read this from a file, or set from GUI
public static final int[] width = new int[1];
public static final int[] height = new int[1];
}
public interface GameType {
public static final String Constructed = "constructed";
public static final String Sealed = "sealed";
public static final String Draft = "draft";
public static final List<String> GameTypes = Collections.unmodifiableList(Arrays.asList(Constructed,
Sealed, Draft));
}
public interface IO {
//TODO: probably should read this from a file, or set from GUI
// public static final String baseDir = "c:\\Tim\\game testing\\";
public static final String deckFile = "all-decks2";
public static final String boosterDeckFile = "booster-decks";
public static final String deckFile = "all-decks2";
public static final String boosterDeckFile = "booster-decks";
public static final String imageBaseDir = "pics";
public static final String cardFile = "cards.txt";
public static final String imageBaseDir = "pics";
public static final String cardFile = "cards.txt";
public static final ImageIcon upIcon = new ImageIcon("up.gif");
public static final ImageIcon downIcon = new ImageIcon("down.gif");
public static final ImageIcon leftIcon = new ImageIcon("left.gif");
public static final ImageIcon rightIcon = new ImageIcon("right.gif");
}
public interface Ability {
public static final String Triggered = "Triggered";
public static final String Activated = "Activated";
}
public interface Phase {
public static final String Untap = "Untap";
public static final String Upkeep = "Upkeep";
public static final String Draw = "Draw";
public static final String Main1 = "Main1";
//public static final String Begin_Combat = "Beginning of Combat";
public static final String Combat_Before_Declare_Attackers_InstantAbility = "Before Attack Phase - Play Instants and Abilities";
public static final String Combat_Declare_Attackers_InstantAbility = "Declare Attackers - Play Instants and Abilities";
public static final String Combat_Declare_Attackers = "Declare Attackers";
public static final String Combat_Declare_Blockers = "Declare Blockers";
public static final String Combat_Declare_Blockers_InstantAbility = "Declare Blockers - Play Instants and Abilities";
public static final String Combat_Damage = "Combat Damage";
public static final String Combat_FirstStrikeDamage = "First Strike Damage";
//public static final String End_Combat = "End of Combat";
public static final String Main2 = "Main2";
public static final String At_End_Of_Turn = "At End of Turn";
public static final String End_Of_Turn = "End of Turn";
public static final String Until_End_Of_Turn = "Until End of Turn";
public static final String Cleanup = "Cleanup";
}
public interface Zone {
public static final String Hand = "Hand";
public static final String Library = "Library";
public static final String Graveyard = "Graveyard";
public static final String Play = "Play";
public static final String Removed_From_Play = "Removed from play";
//public static final String Stack = "Stack";
}
public interface Player {
public static final String Human = "Human";
public static final String Computer = "Computer";
}
public static final ImageIcon upIcon = new ImageIcon ("up.gif");
public static final ImageIcon downIcon = new ImageIcon ("down.gif");
public static final ImageIcon leftIcon = new ImageIcon ("left.gif");
public static final ImageIcon rightIcon = new ImageIcon("right.gif");
}
public interface Ability
{
public static final String Triggered = "Triggered";
public static final String Activated = "Activated";
}
public interface Phase
{
public static final String Untap = "Untap";
public static final String Upkeep = "Upkeep";
public static final String Draw = "Draw";
public static final String Main1 = "Main1";
//public static final String Begin_Combat = "Beginning of Combat";
public static final String Combat_Before_Declare_Attackers_InstantAbility = "Before Attack Phase - Play Instants and Abilities";
public static final String Combat_Declare_Attackers_InstantAbility = "Declare Attackers - Play Instants and Abilities";
public static final String Combat_Declare_Attackers = "Declare Attackers";
public static final String Combat_Declare_Blockers = "Declare Blockers";
public static final String Combat_Declare_Blockers_InstantAbility = "Declare Blockers - Play Instants and Abilities";
public static final String Combat_Damage = "Combat Damage";
public static final String Combat_FirstStrikeDamage = "First Strike Damage";
//public static final String End_Combat = "End of Combat";
public static final String Main2 = "Main2";
public static final String At_End_Of_Turn = "At End of Turn";
public static final String End_Of_Turn = "End of Turn";
public static final String Until_End_Of_Turn = "Until End of Turn";
public static final String Cleanup = "Cleanup";
}
public interface Zone
{
public static final String Hand = "Hand";
public static final String Library = "Library";
public static final String Graveyard = "Graveyard";
public static final String Play = "Play";
public static final String Removed_From_Play = "Removed from play";
//public static final String Stack = "Stack";
}
public interface Player
{
public static final String Human = "Human";
public static final String Computer = "Computer";
}
/*
public interface CardType
{
public static final String Artifact = "Artifact";
public static final String Creature = "Creature";
public static final String Enchantment = "Enchantment";
public static final String Aura = "Aura";
public static final String Instant = "Instant";
public static final String Land = "Land";
public static final String Legendary = "Legendary";
public static final String Sorcery = "Sorcery";
public static final String Basic = "Basic";
public static final String Artifact = "Artifact";
public static final String Creature = "Creature";
public static final String Enchantment = "Enchantment";
public static final String Aura = "Aura";
public static final String Instant = "Instant";
public static final String Land = "Land";
public static final String Legendary = "Legendary";
public static final String Sorcery = "Sorcery";
public static final String Basic = "Basic";
}
*/
public interface Color
{
public static final String Black = "black";
public static final String Blue = "blue";
public static final String Green = "green";
public static final String Red = "red";
public static final String White = "white";
public interface Color {
public static final String Black = "black";
public static final String Blue = "blue";
public static final String Green = "green";
public static final String Red = "red";
public static final String White = "white";
public static final String Colorless = "colorless";
//color order "wubrg"
public static final String Colors[] =
{White, Blue, Black, Red, Green, Colorless};
public static final String Colorless = "colorless";
//color order "wubrg"
public static final String Colors[] = {White, Blue, Black, Red, Green, Colorless};
public static final String onlyColors[] = {White, Blue, Black, Red, Green};
public static final String onlyColors[] = {White, Blue, Black, Red, Green};
public static final String Snow = "snow";
public static final String ManaColors[] =
{White, Blue, Black, Red, Green, Colorless, Snow};
}
public static final String Snow = "snow";
public static final String ManaColors[] = {White, Blue, Black, Red, Green, Colorless, Snow};
}
}//Constant
/*

View File

@@ -1,31 +1,45 @@
package forge;
import static java.util.Collections.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class Deck implements java.io.Serializable {
private static final long serialVersionUID = -2188987217361601903L;
//gameType is from Constant.GameType, like Constant.GameType.Regular
private String deckType;
private String name, comment, deckType;
private boolean isRegular;
private boolean isSealed;
private boolean isDraft;
private ArrayList<String> main = new ArrayList<String>();
private ArrayList<String> sideboard = new ArrayList<String>();
//very important, do NOT change this
private String name = "";
private List<String> main, sideboard, mainView, sideboardView;
//gameType is from Constant.GameType, like Constant.GameType.Regular
public Deck(String gameType) {
deckType = gameType;
setDeckType(gameType);
name = "";
main = new ArrayList<String>();
sideboard = new ArrayList<String>();
mainView = unmodifiableList(main);
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;
}
public List<String> getMain() {
return mainView;
}
public List<String> getSideboard() {
return sideboardView;
}
public String getDeckType() {
@@ -33,14 +47,14 @@ public class Deck implements java.io.Serializable {
}
//can only call this method ONCE
private final void setDeckType(String deckType) {
if(isRegular || isSealed || isDraft) throw new RuntimeException(
private void setDeckType(String deckType) {
if(this.deckType != null) throw new IllegalStateException(
"Deck : setDeckType() error, deck type has already been set");
if(deckType.equals(Constant.GameType.Constructed)) isRegular = true;
else if(deckType.equals(Constant.GameType.Sealed)) isSealed = true;
else if(deckType.equals(Constant.GameType.Draft)) isDraft = true;
else throw new RuntimeException("Deck : setDeckType() error, invalid deck type - " + deckType);
if(!Constant.GameType.GameTypes.contains(deckType)) throw new RuntimeException(
"Deck : setDeckType() error, invalid deck type - " + deckType);
this.deckType = deckType;
}
public void setName(String s) {
@@ -51,6 +65,14 @@ public class Deck implements java.io.Serializable {
return name;
}//may return null
public void setComment(String comment) {
this.comment = comment;
}
public String getComment() {
return comment;
}
public void addMain(String cardName) {
main.add(cardName);
}
@@ -84,21 +106,22 @@ public class Deck implements java.io.Serializable {
}
public boolean isDraft() {
return isDraft;
return deckType.equals(Constant.GameType.Draft);
}
public boolean isSealed() {
return isSealed;
return deckType.equals(Constant.GameType.Sealed);
}
public boolean isRegular() {
return isRegular;
return deckType.equals(Constant.GameType.Constructed);
}
public int hashcode() {
return getName().hashCode();
}
@Override
public String toString() {
return getName();
}

View File

@@ -1,202 +1,45 @@
/**
* DeckIO.java
*
* Created on 01.11.2009
*/
package forge;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import forge.error.ErrorViewer;
/**
* The class DeckIO.
*
* @version V0.0 01.11.2009
* @author Clemens Koza
*/
public interface DeckIO {
//reads and write Deck objects
public class DeckIO {
private final File file;
private ArrayList<Deck> deckList = new ArrayList<Deck>();
public boolean isUnique(String deckName);
//key is String of the humans deck
//data is Deck[] size of 8
//humans deck is Deck[0]
private Map<String, Deck[]> boosterMap = new HashMap<String, Deck[]>();
public boolean isUniqueDraft(String deckName);
public static void main(String[] args) {
Deck[] deck = new Deck[8];
for(int i = 0; i < deck.length; i++) {
deck[i] = new Deck(Constant.GameType.Draft);
deck[i].setName("" + i);
}
public boolean hasName(String deckName);
deck[0].addMain("Lantern Kami");
public Deck readDeck(String deckName);
//DeckIO io = new DeckIO("booster-decks");
// io.writeBoosterDeck(deck);
// io.close();
public void writeDeck(Deck deck);
// io.deleteBoosterDeck("0");
// System.out.println(io.getBoosterDecks().keySet().size());
// io.close();
}
public void deleteDeck(String deckName);
public DeckIO(String filename) {
this(new File(filename));
}
public Deck[] readBoosterDeck(String deckName);
public DeckIO(File file) {
this.file = file;
public void writeBoosterDeck(Deck[] deck);//writeBoosterDeck()
readFile();
}
public void deleteBoosterDeck(String deckName);
public boolean isUnique(String deckName) {
Deck d;
for(int i = 0; i < deckList.size(); i++) {
d = deckList.get(i);
if(d.getName().equals(deckName)) return false;
}
return true;
}
public Deck[] getDecks();
public boolean isUniqueDraft(String deckName) {
ArrayList<String> key = new ArrayList<String>(boosterMap.keySet());
public Map<String, Deck[]> getBoosterDecks();
for(int i = 0; i < key.size(); i++) {
if(key.get(i).equals(deckName)) return false;
}
return true;
}
public void close();
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 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(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 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(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(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 Deck[] getDecks() {
Deck[] out = new Deck[deckList.size()];
deckList.toArray(out);
return out;
}
public Map<String, Deck[]> getBoosterDecks() {
return new HashMap<String, Deck[]>(boosterMap);
}
public void close() {
writeFile();
}
@SuppressWarnings("unchecked")
// ArrayList and Map have unchecked casts
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));
deckList = (ArrayList<Deck>) in.readObject();
boosterMap = (Map<String, Deck[]>) in.readObject();
in.close();
} catch(Exception ex) {
ErrorViewer.showError(ex);
throw new RuntimeException("DeckIO : read() error, " + ex);
}
}
private void writeFile() {
try {
//~
if(file == null) {
return;
}
//~
if(!file.exists()) file.createNewFile();
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(deckList);
out.writeObject(boosterMap);
out.flush();
out.close();
} catch(Exception ex) {
ErrorViewer.showError(ex);
throw new RuntimeException("DeckIO : write() error, " + ex.getMessage());
}
}
}//DeckIO
}

View File

@@ -1,4 +1,7 @@
package forge;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Frame;
@@ -37,7 +40,6 @@ import forge.properties.ForgeProps;
import forge.properties.NewConstants;
public class Gui_BoosterDraft extends JFrame implements CardDetail, NewConstants, NewConstants.LANG.Gui_BoosterDraft {
private static final long serialVersionUID = -6055633915602448260L;
@@ -450,7 +452,7 @@ public class Gui_BoosterDraft extends JFrame implements CardDetail, NewConstants
private void refreshGui() {
Deck deck = Constant.Runtime.HumanDeck[0];
if(deck == null) //this is just a patch, i know
deck = new Deck(Constant.Runtime.GameType[0]);
deck = new Deck(Constant.Runtime.GameType[0]);
allCardModel.clear();
deckModel.clear();
@@ -461,8 +463,7 @@ public class Gui_BoosterDraft extends JFrame implements CardDetail, NewConstants
c = AllZone.CardFactory.getCard(deck.getMain(i), Constant.Player.Human);
//add rarity to card if this is a sealed card pool
if(!Constant.Runtime.GameType[0].equals(Constant.GameType.Constructed))
c.setRarity(pack.getRarity(c.getName()));;
if(!Constant.Runtime.GameType[0].equals(Constant.GameType.Constructed)) c.setRarity(pack.getRarity(c.getName()));;
deckModel.addCard(c);
}//for
@@ -510,7 +511,7 @@ public class Gui_BoosterDraft extends JFrame implements CardDetail, NewConstants
//pick card
int n = allCardTable.getSelectedRow();
if(n == -1) //is valid selection?
return;
return;
Card c = allCardModel.rowToCard(n);
@@ -582,7 +583,8 @@ public class Gui_BoosterDraft extends JFrame implements CardDetail, NewConstants
Deck[] all = {
human, computer[0], computer[1], computer[2], computer[3], computer[4], computer[5], computer[6]};
DeckIO deckIO = new DeckIO(ForgeProps.getFile(BOOSTER_DECKS));
// DeckIO deckIO = new OldDeckIO(ForgeProps.getFile(BOOSTER_DECKS));
DeckIO deckIO = new NewDeckIO(ForgeProps.getFile(NEW_DECKS));
deckIO.writeBoosterDeck(all);
//write file

View File

@@ -51,8 +51,11 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
private final boolean debugPrint = false;
private final DeckIO deckIO = new DeckIO(ForgeProps.getFile(DECKS));
private final DeckIO boosterDeckIO = new DeckIO(ForgeProps.getFile(BOOSTER_DECKS));
// private final DeckIO deckIO = new OldDeckIO(ForgeProps.getFile(DECKS));
// private final DeckIO boosterDeckIO = new OldDeckIO(ForgeProps.getFile(BOOSTER_DECKS));
private final DeckIO deckIO = new NewDeckIO(ForgeProps.getFile(NEW_DECKS));
//with the new IO, there's no reason to use different instances
private final DeckIO boosterDeckIO = deckIO;
private boolean isDeckSaved;
private String currentDeckName;
@@ -329,7 +332,7 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
Object check = null;
try {
ObjectInputStream in = new _ObjectInputStream(new FileInputStream(file));
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
check = in.readObject();
in.close();

View File

@@ -1,5 +1,7 @@
package forge;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
@@ -47,32 +49,35 @@ import forge.properties.NewConstants.LANG.Gui_NewGame.MENU_BAR.OPTIONS;
public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LANG.Gui_NewGame {
private static final long serialVersionUID = -2437047615019135648L;
private final DeckIO deckIO = new DeckIO(ForgeProps.getFile(DECKS));
private final DeckIO boosterDeckIO = new DeckIO(ForgeProps.getFile(BOOSTER_DECKS));
// private final DeckIO deckIO = new OldDeckIO(ForgeProps.getFile(DECKS));
// private final DeckIO boosterDeckIO = new OldDeckIO(ForgeProps.getFile(BOOSTER_DECKS));
private final DeckIO deckIO = new NewDeckIO(ForgeProps.getFile(NEW_DECKS));
//with the new IO, there's no reason to use different instances
private final DeckIO boosterDeckIO = deckIO;
private ArrayList<Deck> allDecks;
private static Gui_DeckEditor editor;
private JLabel titleLabel = new JLabel();
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private JComboBox humanComboBox = new JComboBox();
private JComboBox computerComboBox = new JComboBox();
private JButton deckEditorButton = new JButton();
private JButton startButton = new JButton();
private ButtonGroup buttonGroup1 = new ButtonGroup();
private JRadioButton sealedRadioButton = new JRadioButton();
private JRadioButton singleRadioButton = new JRadioButton();
private JPanel jPanel2 = new JPanel();
private Border border1;
private TitledBorder titledBorder1;
private JRadioButton draftRadioButton = new JRadioButton();
private JPanel jPanel1 = new JPanel();
private Border border2;
private JLabel titleLabel = new JLabel();
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private JComboBox humanComboBox = new JComboBox();
private JComboBox computerComboBox = new JComboBox();
private JButton deckEditorButton = new JButton();
private JButton startButton = new JButton();
private ButtonGroup buttonGroup1 = new ButtonGroup();
private JRadioButton sealedRadioButton = new JRadioButton();
private JRadioButton singleRadioButton = new JRadioButton();
private JPanel jPanel2 = new JPanel();
private Border border1;
private TitledBorder titledBorder1;
private JRadioButton draftRadioButton = new JRadioButton();
private JPanel jPanel1 = new JPanel();
private Border border2;
@SuppressWarnings("unused")
// titledBorder2
private TitledBorder titledBorder2;
private static JCheckBox newGuiCheckBox = new JCheckBox("", true);
private static JCheckBox smoothLandCheckBox = new JCheckBox("", true);
private TitledBorder titledBorder2;
private static JCheckBox newGuiCheckBox = new JCheckBox("", true);
private static JCheckBox smoothLandCheckBox = new JCheckBox("", true);
// GenerateConstructedDeck.get2Colors() and GenerateSealedDeck.get2Colors()
// use these two variables
@@ -81,7 +86,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
public static JCheckBoxMenuItem removeArtifacts = new JCheckBoxMenuItem(
ForgeProps.getLocalized(MENU_BAR.OPTIONS.GENERATE.REMOVE_ARTIFACTS));
private JButton questButton = new JButton();
private JButton questButton = new JButton();
private Action LOOK_AND_FEEL_ACTION = new LookAndFeelAction(this);
private Action DOWNLOAD_ACTION = new DownloadAction();
@@ -90,7 +95,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
public static void main(String[] args) {
ExceptionHandler.registerErrorHandling();
try {
try {
Object[] o = UIManager.getInstalledLookAndFeels();
if(o.length > 3) {
final Color background = new Color(204, 204, 204);
@@ -102,7 +107,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
"Dialog.background", "OptionPane.background", "ScrollBar.background"};
for(int i = 0; i < properties.length; i++) {
//UIManager.put(properties, background);
UIManager.put(properties[i], background);
UIManager.put(properties[i], background);
}
}
} catch(Exception ex) {
@@ -402,19 +407,15 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
if(humanGenerate) {
if(constructed) Constant.Runtime.HumanDeck[0] = generateConstructedDeck();
else if(sealed) Constant.Runtime.HumanDeck[0] = generateSealedDeck();
}
else if (humanGenerateMulti3) {
if(constructed) Constant.Runtime.HumanDeck[0] = generateConstructed3ColorDeck();
}
else if (humanGenerateMulti5) {
if(constructed) Constant.Runtime.HumanDeck[0] = generateConstructed5ColorDeck();
}
else if(humanRandom) {
} else if(humanGenerateMulti3) {
if(constructed) Constant.Runtime.HumanDeck[0] = generateConstructed3ColorDeck();
} else if(humanGenerateMulti5) {
if(constructed) Constant.Runtime.HumanDeck[0] = generateConstructed5ColorDeck();
} else if(humanRandom) {
Constant.Runtime.HumanDeck[0] = getRandomDeck(getDecks(format));
JOptionPane.showMessageDialog(null, String.format("You are using deck: %s",
Constant.Runtime.HumanDeck[0].getName()), "Deck Name", JOptionPane.INFORMATION_MESSAGE);
}
else {
} else {
Constant.Runtime.HumanDeck[0] = deckIO.readDeck(human);
}
@@ -427,14 +428,11 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
if(computerGenerate) {
if(constructed) Constant.Runtime.ComputerDeck[0] = generateConstructedDeck();
else if(sealed) Constant.Runtime.ComputerDeck[0] = generateSealedDeck();
}
else if (computerGenerateMulti3) {
if(constructed) Constant.Runtime.ComputerDeck[0] = generateConstructed3ColorDeck();
}
else if (computerGenerateMulti5) {
if(constructed) Constant.Runtime.ComputerDeck[0] = generateConstructed5ColorDeck();
}
else if(computerRandom) {
} else if(computerGenerateMulti3) {
if(constructed) Constant.Runtime.ComputerDeck[0] = generateConstructed3ColorDeck();
} else if(computerGenerateMulti5) {
if(constructed) Constant.Runtime.ComputerDeck[0] = generateConstructed5ColorDeck();
} else if(computerRandom) {
Constant.Runtime.ComputerDeck[0] = getRandomDeck(getDecks(format));
JOptionPane.showMessageDialog(null, String.format("The computer is using deck: %s",
Constant.Runtime.ComputerDeck[0].getName()), "Deck Name", JOptionPane.INFORMATION_MESSAGE);
@@ -479,7 +477,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
}
private Deck generateConstructed3ColorDeck() {
GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
CardList name = gen.generate3ColorDeck();
Deck deck = new Deck(Constant.GameType.Constructed);
@@ -489,7 +487,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
}
private Deck generateConstructed5ColorDeck() {
GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
GenerateConstructedMultiColorDeck gen = new GenerateConstructedMultiColorDeck();
CardList name = gen.generate5ColorDeck();
Deck deck = new Deck(Constant.GameType.Constructed);
@@ -581,8 +579,8 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
public static class LookAndFeelAction extends AbstractAction {
private static final long serialVersionUID = -4447498333866711215L;
private Component c;
private static final long serialVersionUID = -4447498333866711215L;
private Component c;
public LookAndFeelAction(Component c) {
super(ForgeProps.getLocalized(MENU_BAR.MENU.LF));
@@ -608,9 +606,9 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
public static class DownloadAction extends AbstractAction {
private static final long serialVersionUID = 6564425021778307101L;
private static final long serialVersionUID = 6564425021778307101L;
public DownloadAction() {
public DownloadAction() {
super(ForgeProps.getLocalized(MENU_BAR.MENU.DOWNLOAD));
}
@@ -621,10 +619,10 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
public static class CardSizesAction extends AbstractAction {
private static final long serialVersionUID = -2900235618450319571L;
private String[] keys = {"Tiny", "Small", "Medium", "Large"};
private int[] widths = {42, 63, 70, 93};
private int[] heights = {59, 88, 98, 130};
private static final long serialVersionUID = -2900235618450319571L;
private String[] keys = {"Tiny", "Small", "Medium", "Large"};
private int[] widths = {42, 63, 70, 93};
private int[] heights = {59, 88, 98, 130};
public CardSizesAction() {
super(ForgeProps.getLocalized(MENU_BAR.MENU.CARD_SIZES));
@@ -645,9 +643,9 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
public static class AboutAction extends AbstractAction {
private static final long serialVersionUID = 5492173304463396871L;
private static final long serialVersionUID = 5492173304463396871L;
public AboutAction() {
public AboutAction() {
super(ForgeProps.getLocalized(MENU_BAR.MENU.ABOUT));
}

View File

@@ -264,7 +264,7 @@ public class Gui_Quest_DeckEditor_Menu extends JMenuBar {
Object check = null;
try {
ObjectInputStream in = new _ObjectInputStream(new FileInputStream(file));
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
check = in.readObject();
in.close();

View File

@@ -39,7 +39,7 @@ public class IO {
// Map has unchecked cast
private void readMap() {
try {
ObjectInputStream in = new _ObjectInputStream(new FileInputStream(file));
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
map = (Map<String, Serializable>) in.readObject();
in.close();
} catch(Exception ex) {

327
src/forge/NewDeckIO.java Executable file
View File

@@ -0,0 +1,327 @@
package forge;
import static java.lang.Integer.*;
import static java.lang.String.*;
import static java.util.Arrays.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
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 java.util.regex.Matcher;
import java.util.regex.Pattern;
import forge.error.ErrorViewer;
//reads and write Deck objects
public class NewDeckIO implements DeckIO {
private static FilenameFilter dck = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".dck");
}
};
private static FilenameFilter bdk = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".bdk");
}
};
private File dir;
List<Deck> deckList;
Map<String, Deck[]> boosterMap;
public NewDeckIO(String fileName) {
this(new File(fileName));
}
public NewDeckIO(File dir) {
try {
this.dir = dir;
if(dir.isFile()) {
throw new IOException("Not a directory");
} else {
dir.mkdirs();
if(!dir.isDirectory()) throw new IOException("Directory can't be created");
deckList = new ArrayList<Deck>();
boosterMap = new HashMap<String, Deck[]>();
readFile();
}
} catch(IOException ex) {
ErrorViewer.showError(ex);
throw new RuntimeException("DeckIO : write() error, " + ex.getMessage());
}
}
public boolean isUnique(String deckName) {
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 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(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 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(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(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 Deck[] getDecks() {
Deck[] out = new Deck[deckList.size()];
deckList.toArray(out);
return out;
}
public Map<String, Deck[]> getBoosterDecks() {
return new HashMap<String, Deck[]>(boosterMap);
}
public void close() {
writeFile();
}
public void readFile() {
try {
deckList.clear();
File[] files;
files = dir.listFiles(dck);
for(File file:files) {
BufferedReader in = new BufferedReader(new FileReader(file));
deckList.add(read(in));
in.close();
}
boosterMap.clear();
files = dir.listFiles(bdk);
for(File file:files) {
Deck[] d = new Deck[8];
for(int i = 0; i < d.length; i++) {
BufferedReader in = new BufferedReader(new FileReader(new File(file, i + ".dck")));
d[i] = read(in);
in.close();
}
boosterMap.put(d[0].getName(), d);
}
} catch(IOException ex) {
ErrorViewer.showError(ex);
throw new RuntimeException("DeckIO : read() error, " + ex.getMessage());
}
}
private Deck read(BufferedReader in) throws IOException {
String line;
//read name
String name = in.readLine();
if(name == null) throw new IOException("Unexpected end of file");
//read comments
String comment = null;
while((line = in.readLine()) != null && !line.equals("[general]")) {
if(comment == null) comment = line;
else comment += "\n" + line;
}
//read deck type
String deckType = in.readLine();
if(deckType == null) throw new IOException("Unexpected end of file");
Deck d = new Deck(deckType);
d.setName(name);
d.setComment(comment);
//go to [main]
while((line = in.readLine()) != null && !line.equals("[main]"))
System.err.println("unexpected line: " + line);
if(line == null) throw new IOException("Unexpected end of file");
Pattern p = Pattern.compile("\\s*((\\d+)\\s+)?(.*?)\\s*");
//read main deck
while((line = in.readLine()) != null && !line.equals("[sideboard]")) {
Matcher m = p.matcher(line);
if(!m.matches()) throw new IOException("unexpected line: " + line);
String s = m.group(2);
int count = s == null? 1:parseInt(s);
for(int i = 0; i < count; i++) {
d.addMain(m.group(3));
}
}
if(line == null) throw new IOException("Unexpected end of file");
//read sideboard
while((line = in.readLine()) != null && line.length() != 0) {
Matcher m = p.matcher(line);
if(!m.matches()) throw new IOException("unexpected line: " + line);
String s = m.group(2);
int count = s == null? 1:parseInt(s);
for(int i = 0; i < count; i++) {
d.addSideboard(m.group(3));
}
}
return d;
}
private String deriveFileName(String deckName) {
//skips all but the listed characters
return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", "");
}
public void writeFile() {
try {
//store the files that do exist
List<File> files = new ArrayList<File>();
files.addAll(asList(dir.listFiles(dck)));
//save the files and remove them from the list
for(Deck deck:deckList) {
File f = new File(dir, deriveFileName(deck.getName()) + ".dck");
files.remove(f);
BufferedWriter out = new BufferedWriter(new FileWriter(f));
write(deck, out);
out.close();
}
//delete the files that were not written out: the decks that were deleted
for(File file:files)
file.delete();
//store the files that do exist
files.clear();
files.addAll(asList(dir.listFiles(bdk)));
//save the files and remove them from the list
for(Entry<String, Deck[]> e:boosterMap.entrySet()) {
File f = new File(dir, deriveFileName(e.getValue()[0].getName()) + ".bdk");
f.mkdir();
for(int i = 0; i < e.getValue().length; i++) {
BufferedWriter out = new BufferedWriter(new FileWriter(new File(f, i + ".dck")));
write(e.getValue()[i], out);
out.close();
}
}
//delete the files that were not written out: the decks that were deleted
for(File file:files) {
for(int i = 0; i < 8; i++)
new File(file, i + ".dck").delete();
file.delete();
}
} catch(IOException ex) {
ErrorViewer.showError(ex);
throw new RuntimeException("DeckIO : write() error, " + ex.getMessage());
}
}
private void write(Deck d, BufferedWriter out) throws IOException {
out.write(format("%s%n", d.getName()));
if(d.getComment() != null) out.write(format("%s%n", d.getComment()));
out.write(format("%s%n", "[general]"));
out.write(format("%s%n", d.getDeckType()));
out.write(format("%s%n", "[main]"));
for(Entry<String, Integer> e:count(d.getMain()).entrySet()) {
out.write(format("%d %s%n", e.getValue(), e.getKey()));
}
out.write(format("%s%n", "[sideboard]"));
for(Entry<String, Integer> e:count(d.getSideboard()).entrySet()) {
out.write(format("%d %s%n", e.getValue(), e.getKey()));
}
}
private Map<String, Integer> count(List<String> src) {
Map<String, Integer> result = new HashMap<String, Integer>();
for(String s:src) {
Integer dstValue = result.get(s);
if(dstValue == null) result.put(s, 1);
else result.put(s, dstValue.intValue() + 1);
}
return result;
}
}

View File

@@ -66,7 +66,7 @@ public class NewIO {
private ObjectInputStream getReader() {
try {
return new _ObjectInputStream(new FileInputStream(file));
return new ObjectInputStream(new FileInputStream(file));
} catch(IOException ex) {
ErrorViewer.showError(ex);
throw new RuntimeException("IO : getReader() - error - " + ex);

202
src/forge/OldDeckIO.java Normal file
View File

@@ -0,0 +1,202 @@
package forge;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import forge.error.ErrorViewer;
//reads and write Deck objects
public class OldDeckIO implements DeckIO {
private final File file;
private ArrayList<Deck> deckList = new ArrayList<Deck>();
//key is String of the humans deck
//data is Deck[] size of 8
//humans deck is Deck[0]
private Map<String, Deck[]> boosterMap = new HashMap<String, Deck[]>();
public static void main(String[] args) {
Deck[] deck = new Deck[8];
for(int i = 0; i < deck.length; i++) {
deck[i] = new Deck(Constant.GameType.Draft);
deck[i].setName("" + i);
}
deck[0].addMain("Lantern Kami");
//DeckIO io = new DeckIO("booster-decks");
// io.writeBoosterDeck(deck);
// io.close();
// io.deleteBoosterDeck("0");
// System.out.println(io.getBoosterDecks().keySet().size());
// io.close();
}
public OldDeckIO(String filename) {
this(new File(filename));
}
public OldDeckIO(File file) {
this.file = file;
readFile();
}
public boolean isUnique(String deckName) {
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 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(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 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(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(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 Deck[] getDecks() {
Deck[] out = new Deck[deckList.size()];
deckList.toArray(out);
return out;
}
public Map<String, Deck[]> getBoosterDecks() {
return new HashMap<String, Deck[]>(boosterMap);
}
public void close() {
writeFile();
}
@SuppressWarnings("unchecked")
// ArrayList and Map have unchecked casts
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));
deckList = (ArrayList<Deck>) in.readObject();
boosterMap = (Map<String, Deck[]>) in.readObject();
in.close();
} catch(Exception ex) {
ErrorViewer.showError(ex);
throw new RuntimeException("DeckIO : read() error, " + ex);
}
}
private void writeFile() {
try {
//~
if(file == null) {
return;
}
//~
if(!file.exists()) file.createNewFile();
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(deckList);
out.writeObject(boosterMap);
out.flush();
out.close();
} catch(Exception ex) {
ErrorViewer.showError(ex);
throw new RuntimeException("DeckIO : write() error, " + ex.getMessage());
}
}
}//DeckIO

View File

@@ -195,7 +195,7 @@ public class QuestData implements NewConstants {
static public QuestData loadData() {
try {
//read file "questData"
ObjectInputStream in = new _ObjectInputStream(new FileInputStream(ForgeProps.getFile(QUEST.DATA)));
ObjectInputStream in = new ObjectInputStream(new FileInputStream(ForgeProps.getFile(QUEST.DATA)));
Object o = in.readObject();
in.close();

View File

@@ -1,39 +0,0 @@
/**
* _ObjectInputStream.java
*
* Created on 29.10.2009
*/
package forge;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
/**
* The class _ObjectInputStream.
*
* @version V0.0 29.10.2009
* @author Clemens Koza
*/
public class _ObjectInputStream extends ObjectInputStream {
public _ObjectInputStream() throws IOException {
super();
enableResolveObject(true);
}
public _ObjectInputStream(InputStream is) throws IOException {
super(is);
enableResolveObject(true);
}
@Override
protected Object resolveObject(Object obj) throws IOException {
Class<?> c = obj.getClass().getComponentType();
if(c != null && "Deck".equals(c.getName())) {
return new Deck[((Object[]) obj).length];
} else return obj;
}
}

View File

@@ -22,6 +22,7 @@ public interface NewConstants {
public static final String DECKS = "decks";
public static final String BOOSTER_DECKS = "booster-decks";
public static final String NEW_DECKS = "decks-dir";
public static final String TOKENS = "tokens";
public static final String CARD_PICTURES = "card-pictures";