mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Removed old Serialization-based Decks.
Refactored Deck class to a better package. Renamed NewDeckIO to DeckManager. Removed DeckIO interface as it is no longer needed Simplified much of the Deck Manager code. Added hooks for new Deck file format. Added metadata info to Deck class.
This commit is contained in:
@@ -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,91 +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.OldDeckIO;
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import javax.swing.JOptionPane;
|
||||
import forge.gui.GuiUtils;
|
||||
|
||||
|
||||
import forge.deck.Deck;
|
||||
|
||||
public interface BoosterDraft
|
||||
{
|
||||
public CardList nextChoice();
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package forge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
|
||||
import forge.deck.Deck;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -660,4 +664,4 @@ class deckColors {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package forge;
|
||||
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.quest.data.QuestMatchState;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
|
||||
package forge;
|
||||
|
||||
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
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 name, comment, deckType;
|
||||
|
||||
private List<String> main, sideboard, mainView, sideboardView;
|
||||
|
||||
//gameType is from Constant.GameType, like Constant.GameType.Regular
|
||||
public Deck(String gameType) {
|
||||
setDeckType(gameType);
|
||||
name = "";
|
||||
|
||||
main = 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.name = name;
|
||||
|
||||
this.main = main;
|
||||
mainView = unmodifiableList(main);
|
||||
|
||||
this.sideboard = main;
|
||||
sideboardView = unmodifiableList(sideboard);
|
||||
}
|
||||
|
||||
public List<String> getMain() {
|
||||
return mainView;
|
||||
}
|
||||
|
||||
public List<String> getSideboard() {
|
||||
return sideboardView;
|
||||
}
|
||||
|
||||
public String getDeckType() {
|
||||
return deckType;
|
||||
}
|
||||
|
||||
//can only call this method ONCE
|
||||
private void setDeckType(String deckType) {
|
||||
if(this.deckType != null) throw new IllegalStateException(
|
||||
"Deck : setDeckType() error, deck type has already been set");
|
||||
|
||||
if(!Constant.GameType.GameTypes.contains(deckType)) throw new RuntimeException(
|
||||
"Deck : setDeckType() error, invalid deck type - " + deckType);
|
||||
|
||||
this.deckType = deckType;
|
||||
}
|
||||
|
||||
public void setName(String s) {
|
||||
name = s;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
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);
|
||||
}
|
||||
|
||||
public int countMain() {
|
||||
return main.size();
|
||||
}
|
||||
|
||||
public String getMain(int index) {
|
||||
return main.get(index).toString();
|
||||
}
|
||||
|
||||
public String removeMain(int index) {
|
||||
return main.remove(index).toString();
|
||||
}
|
||||
|
||||
public void removeMain(Card c)
|
||||
{
|
||||
if (main.contains(c.getName()))
|
||||
{
|
||||
int i = main.indexOf(c.getName());
|
||||
main.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void addSideboard(String cardName) {
|
||||
sideboard.add(cardName);
|
||||
}
|
||||
|
||||
public int countSideboard() {
|
||||
return sideboard.size();
|
||||
}
|
||||
|
||||
public String getSideboard(int index) {
|
||||
return sideboard.get(index).toString();
|
||||
}
|
||||
|
||||
public String removeSideboard(int index) {
|
||||
return sideboard.remove(index).toString();
|
||||
}
|
||||
|
||||
public boolean isDraft() {
|
||||
return deckType.equals(Constant.GameType.Draft);
|
||||
}
|
||||
|
||||
public boolean isSealed() {
|
||||
return deckType.equals(Constant.GameType.Sealed);
|
||||
}
|
||||
|
||||
public boolean isRegular() {
|
||||
return deckType.equals(Constant.GameType.Constructed);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return getName().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DeckSort implements Comparator<Object>, java.io.Serializable {
|
||||
private static final long serialVersionUID = 6988753027196688633L;
|
||||
|
||||
public int compare(Object a, Object b) {
|
||||
String a1 = ((Deck) a).getName();
|
||||
String b1 = ((Deck) b).getName();
|
||||
|
||||
return a1.compareTo(b1);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* DeckIO.java
|
||||
*
|
||||
* Created on 01.11.2009
|
||||
*/
|
||||
|
||||
package forge;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* The class DeckIO.
|
||||
*
|
||||
* @version V0.0 01.11.2009
|
||||
* @author Clemens Koza
|
||||
*/
|
||||
public interface DeckIO {
|
||||
|
||||
public boolean isUnique(String deckName);
|
||||
|
||||
public boolean isUniqueDraft(String deckName);
|
||||
|
||||
public boolean hasName(String deckName);
|
||||
|
||||
public Deck readDeck(String deckName);
|
||||
|
||||
public void writeDeck(Deck deck);
|
||||
|
||||
public void deleteDeck(String deckName);
|
||||
|
||||
public Deck[] readBoosterDeck(String deckName);
|
||||
|
||||
public void writeBoosterDeck(Deck[] deck);//writeBoosterDeck()
|
||||
|
||||
public void deleteBoosterDeck(String deckName);
|
||||
|
||||
public Deck[] getDecks();
|
||||
|
||||
public Map<String, Deck[]> getBoosterDecks();
|
||||
|
||||
public void close();
|
||||
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
package forge;
|
||||
|
||||
public class DownloadDeck {
|
||||
|
||||
private Card DownloadCard;
|
||||
|
||||
public String FoundNumberCard(String rStr)
|
||||
{
|
||||
int temp;
|
||||
int i;
|
||||
|
||||
for(i=0; i<rStr.length();i++)
|
||||
{
|
||||
temp=rStr.codePointAt(i) ;
|
||||
if(temp>=48 && temp<=57)
|
||||
{
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if(rStr.codePointAt(i+1)>=48 &&rStr.codePointAt(i+1)<=57)
|
||||
{
|
||||
return rStr.substring(i,i+2);
|
||||
}else
|
||||
{
|
||||
return rStr.substring(i,i+1);
|
||||
}
|
||||
}
|
||||
|
||||
public String FoundNameCard(String rStr)
|
||||
{
|
||||
int temp;
|
||||
int i;
|
||||
|
||||
for(i=0; i<rStr.length();i++)
|
||||
{
|
||||
temp=rStr.codePointAt(i) ;
|
||||
if(temp>=48 && temp<=57)
|
||||
{
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return rStr.substring(0,i-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String RemoveSpace(String rStr)
|
||||
{
|
||||
int temp;
|
||||
int i;
|
||||
|
||||
for(i=0; i<rStr.length();i++)
|
||||
{
|
||||
temp=rStr.codePointAt(i) ;
|
||||
if(temp!=32)
|
||||
{
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return rStr.substring(i);
|
||||
}
|
||||
public String RemoveSpaceBack(String rStr)
|
||||
{
|
||||
int temp;
|
||||
int i;
|
||||
|
||||
for(i=rStr.length()-1; i>-1;i=i-1)
|
||||
{
|
||||
temp=rStr.codePointAt(i) ;
|
||||
if(temp!=32)
|
||||
{
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return rStr.substring(0,i+1);
|
||||
}
|
||||
|
||||
public String RemoveFoundNumberCard(String rStr, String Number)
|
||||
{
|
||||
int a;
|
||||
int temp;
|
||||
a=rStr.indexOf(Number);
|
||||
temp=rStr.codePointAt(a+1) ;
|
||||
if(temp>=48 && temp<=57)
|
||||
{
|
||||
return rStr.substring(a+2);
|
||||
}else
|
||||
{
|
||||
return rStr.substring(a+1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String RemoveFoundNameCard(String rStr, String Name)
|
||||
{
|
||||
int a;
|
||||
a=Name.length();
|
||||
return rStr.substring(a);
|
||||
|
||||
}
|
||||
|
||||
public boolean IsCardSupport(String CardName)
|
||||
{
|
||||
CardList all = AllZone.CardFactory.getAllCards();
|
||||
|
||||
Card gCard;
|
||||
for(int i=0;i<all.size();i++)
|
||||
{
|
||||
gCard = all.getCard(i);
|
||||
if(CardName.equalsIgnoreCase(gCard.getName()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Card GetCardDownload(Card c, String CardName)
|
||||
{
|
||||
CardList all = AllZone.CardFactory.getAllCards();
|
||||
|
||||
|
||||
for(int i=0;i<all.size();i++)
|
||||
{
|
||||
DownloadCard = all.getCard(i);
|
||||
|
||||
if(CardName.equalsIgnoreCase(DownloadCard.getName()))
|
||||
{
|
||||
return DownloadCard;
|
||||
}
|
||||
}
|
||||
return DownloadCard;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,15 +6,9 @@ import forge.card.cardFactory.CardFactory;
|
||||
import forge.card.cardFactory.CardFactoryUtil;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.card.mana.ManaPool;
|
||||
import forge.card.spellability.Ability;
|
||||
import forge.card.spellability.Ability_Static;
|
||||
import forge.card.spellability.Cost;
|
||||
import forge.card.spellability.Cost_Payment;
|
||||
import forge.card.spellability.Spell;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.SpellAbility_Requirements;
|
||||
import forge.card.spellability.Target_Selection;
|
||||
import forge.card.spellability.*;
|
||||
import forge.card.trigger.Trigger;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.generate.GenerateConstructedDeck;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.input.Input_Mulligan;
|
||||
|
||||
@@ -2,42 +2,26 @@
|
||||
package forge;
|
||||
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.event.TableModelListener;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.game.CardDetailPanel;
|
||||
import forge.gui.game.CardPicturePanel;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.event.TableModelEvent;
|
||||
import javax.swing.event.TableModelListener;
|
||||
import java.awt.Color;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.*;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class Gui_BoosterDraft extends JFrame implements CardContainer, NewConstants, NewConstants.LANG.Gui_BoosterDraft {
|
||||
private static final long serialVersionUID = -6055633915602448260L;
|
||||
@@ -574,12 +558,11 @@ public class Gui_BoosterDraft extends JFrame implements CardContainer, NewConsta
|
||||
Deck[] all = {
|
||||
human, computer[0], computer[1], computer[2], computer[3], computer[4], computer[5], computer[6]};
|
||||
|
||||
// DeckIO deckIO = new OldDeckIO(ForgeProps.getFile(BOOSTER_DECKS));
|
||||
DeckIO deckIO = new NewDeckIO(ForgeProps.getFile(NEW_DECKS));
|
||||
deckIO.writeBoosterDeck(all);
|
||||
DeckManager deckManager = new DeckManager(ForgeProps.getFile(NEW_DECKS));
|
||||
deckManager.writeBoosterDeck(all);
|
||||
|
||||
//write file
|
||||
deckIO.close();
|
||||
deckManager.close();
|
||||
|
||||
//close and open next screen
|
||||
dispose();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package forge;
|
||||
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.game.CardDetailPanel;
|
||||
import forge.gui.game.CardPicturePanel;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -3,13 +3,9 @@ package forge;
|
||||
import arcane.ui.util.ManaSymbols;
|
||||
import arcane.util.MultiplexOutputStream;
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
|
||||
import forge.deck.generate.Generate2ColorDeck;
|
||||
import forge.deck.generate.Generate3ColorDeck;
|
||||
import forge.deck.generate.GenerateConstructedDeck;
|
||||
import forge.deck.generate.GenerateConstructedMultiColorDeck;
|
||||
import forge.deck.generate.GenerateSealedDeck;
|
||||
import forge.deck.generate.GenerateThemeDeck;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.deck.generate.*;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.error.ExceptionHandler;
|
||||
import forge.gui.GuiUtils;
|
||||
@@ -43,10 +39,10 @@ import java.util.*;
|
||||
public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LANG.Gui_NewGame {
|
||||
private static final long serialVersionUID = -2437047615019135648L;
|
||||
|
||||
private final DeckIO deckIO = new NewDeckIO(ForgeProps.getFile(NEW_DECKS));
|
||||
private final DeckManager deckManager = new DeckManager(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 final DeckManager boosterDeckManager = deckManager;
|
||||
private List<Deck> allDecks;
|
||||
private static Gui_DeckEditor editor;
|
||||
|
||||
private JLabel titleLabel = new JLabel();
|
||||
@@ -247,13 +243,10 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
|
||||
|
||||
// returns, ArrayList of Deck objects
|
||||
private ArrayList<Deck> getDecks() {
|
||||
ArrayList<Deck> list = new ArrayList<Deck>();
|
||||
Deck[] deck = deckIO.getDecks();
|
||||
for(int i = 0; i < deck.length; i++)
|
||||
list.add(deck[i]);
|
||||
private List<Deck> getDecks() {
|
||||
List<Deck> list = new ArrayList<Deck>(deckManager.getDecks());
|
||||
|
||||
Collections.sort(list, new DeckSort());
|
||||
Collections.sort(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -545,7 +538,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
return;
|
||||
} else//load old draft
|
||||
{
|
||||
Deck[] deck = boosterDeckIO.readBoosterDeck(human);
|
||||
Deck[] deck = boosterDeckManager.readBoosterDeck(human);
|
||||
int index = Integer.parseInt(computer);
|
||||
|
||||
Constant.Runtime.HumanDeck[0] = deck[0];
|
||||
@@ -583,7 +576,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
JOptionPane.showMessageDialog(null, String.format("You are using deck: %s",
|
||||
Constant.Runtime.HumanDeck[0].getName()), "Deck Name", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
Constant.Runtime.HumanDeck[0] = deckIO.readDeck(human);
|
||||
Constant.Runtime.HumanDeck[0] = deckManager.readDeck(human);
|
||||
}
|
||||
|
||||
|
||||
@@ -610,7 +603,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
JOptionPane.showMessageDialog(null, String.format("The computer is using deck: %s",
|
||||
Constant.Runtime.ComputerDeck[0].getName()), "Deck Name", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
Constant.Runtime.ComputerDeck[0] = deckIO.readDeck(computer);
|
||||
Constant.Runtime.ComputerDeck[0] = deckManager.readDeck(computer);
|
||||
}
|
||||
}// else
|
||||
|
||||
@@ -894,7 +887,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
computerComboBox.removeAllItems();
|
||||
|
||||
humanComboBox.addItem("New Draft");
|
||||
Object[] key = boosterDeckIO.getBoosterDecks().keySet().toArray();
|
||||
Object[] key = boosterDeckManager.getBoosterDecks().keySet().toArray();
|
||||
Arrays.sort(key);
|
||||
for(int i = 0; i < key.length; i++)
|
||||
humanComboBox.addItem(key[i]);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package forge;
|
||||
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.game.CardDetailPanel;
|
||||
import forge.gui.game.CardPicturePanel;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package forge;
|
||||
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.quest.data.QuestBattleManager;
|
||||
@@ -369,85 +370,83 @@ public class Gui_Quest_DeckEditor_Menu extends JMenuBar {
|
||||
|
||||
return filter;
|
||||
}//getFileFilter()
|
||||
|
||||
|
||||
private File getExportFilename() {
|
||||
//Object o = null; // unused
|
||||
|
||||
|
||||
JFileChooser save = new JFileChooser(previousDirectory);
|
||||
|
||||
|
||||
save.setDialogTitle("Export Deck Filename");
|
||||
save.setDialogType(JFileChooser.SAVE_DIALOG);
|
||||
save.addChoosableFileFilter(getFileFilter());
|
||||
save.setSelectedFile(new File(currentDeck.getName() + ".deck"));
|
||||
|
||||
|
||||
int returnVal = save.showSaveDialog(null);
|
||||
|
||||
|
||||
if(returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File file = save.getSelectedFile();
|
||||
String check = file.getAbsolutePath();
|
||||
|
||||
|
||||
previousDirectory = file.getParentFile();
|
||||
|
||||
|
||||
if(check.endsWith(".deck")) return file;
|
||||
else return new File(check + ".deck");
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}//getExportFilename()
|
||||
|
||||
|
||||
private void importDeck(boolean isHumanDeck) {
|
||||
File file = getImportFilename();
|
||||
|
||||
|
||||
if(file == null) return;
|
||||
|
||||
|
||||
Object check = null;
|
||||
|
||||
|
||||
try {
|
||||
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
|
||||
check = in.readObject();
|
||||
|
||||
|
||||
//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 Object toForgeDeck(Object o) of DeckConverter
|
||||
check = deckConverterClass.getDeclaredMethod("toForgeDeck", Object.class).invoke(null, check);
|
||||
|
||||
|
||||
in.close();
|
||||
} catch(Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("Gui_Quest_DeckEditor_Menu : importDeck() error, " + ex);
|
||||
}
|
||||
|
||||
|
||||
Deck deck = (Deck) check;
|
||||
|
||||
|
||||
deckDisplay.setTitle(deckEditorName + " - " + deck.getName());
|
||||
|
||||
|
||||
CardList cardpool;
|
||||
|
||||
|
||||
if(isHumanDeck) {
|
||||
questData.addDeck(deck);
|
||||
|
||||
|
||||
//convert ArrayList of card names (Strings), into Card objects
|
||||
cardpool = new CardList();
|
||||
List<String> list = questData.getCardpool();
|
||||
|
||||
for(int i = 0; i < list.size(); i++) {
|
||||
String cardName = list.get(i);
|
||||
String setCode = "";
|
||||
if (cardName.contains("|"))
|
||||
{
|
||||
String s[] = cardName.split("\\|",2);
|
||||
cardName = s[0];
|
||||
setCode = s[1];
|
||||
|
||||
for (String cardName : list) {
|
||||
String setCode = "";
|
||||
if (cardName.contains("|")) {
|
||||
String s[] = cardName.split("\\|", 2);
|
||||
cardName = s[0];
|
||||
setCode = s[1];
|
||||
}
|
||||
|
||||
cardpool.add(AllZone.CardFactory.getCard(cardName, null));
|
||||
|
||||
cardpool.add(AllZone.CardFactory.getCard(cardName, null));
|
||||
}
|
||||
} else {
|
||||
QuestBattleManager.addAIDeck(deck);
|
||||
cardpool = AllZone.CardFactory.getAllCards();
|
||||
}
|
||||
|
||||
|
||||
//convert Deck main to CardList
|
||||
CardList deckList = new CardList();
|
||||
for(int i = 0; i < deck.countMain(); i++) {
|
||||
@@ -459,30 +458,30 @@ public class Gui_Quest_DeckEditor_Menu extends JMenuBar {
|
||||
cardName = s[0];
|
||||
setCode = s[1];
|
||||
}
|
||||
|
||||
|
||||
deckList.add(AllZone.CardFactory.getCard(cardName, null));
|
||||
}
|
||||
//update gui
|
||||
deckDisplay.updateDisplay(cardpool, deckList);
|
||||
|
||||
|
||||
}//importDeck()
|
||||
|
||||
|
||||
|
||||
private File getImportFilename() {
|
||||
JFileChooser chooser = new JFileChooser(previousDirectory);
|
||||
|
||||
|
||||
chooser.addChoosableFileFilter(getFileFilter());
|
||||
int returnVal = chooser.showOpenDialog(null);
|
||||
|
||||
|
||||
if(returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
File file = chooser.getSelectedFile();
|
||||
previousDirectory = file.getParentFile();
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}//openFileDialog()
|
||||
|
||||
|
||||
//edit the AI decks
|
||||
private void setupComputerMenu() {
|
||||
JMenuItem open = new JMenuItem("Open");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package forge;
|
||||
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
@@ -1,377 +0,0 @@
|
||||
|
||||
package forge;
|
||||
|
||||
|
||||
import static java.lang.Integer.parseInt;
|
||||
import static java.lang.String.format;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
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) {
|
||||
if(dir == null) throw new IllegalArgumentException("No deck directory specified");
|
||||
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");
|
||||
this.deckList = new ArrayList<Deck>();
|
||||
this.boosterMap = new HashMap<String, Deck[]>();
|
||||
readFile();
|
||||
}
|
||||
} catch(IOException ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("DeckIO : write() error, " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public NewDeckIO(File dir, List<Deck> deckList, Map<String, Deck[]> boosterMap) {
|
||||
this(dir);
|
||||
this.deckList.addAll(deckList);
|
||||
this.boosterMap.putAll(boosterMap);
|
||||
}
|
||||
|
||||
public NewDeckIO(File dir, boolean quest)
|
||||
{
|
||||
if(dir == null) throw new IllegalArgumentException("No deck directory specified");
|
||||
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");
|
||||
this.deckList = new ArrayList<Deck>();
|
||||
readQuestFile();
|
||||
}
|
||||
} 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 readQuestFile() {
|
||||
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();
|
||||
}
|
||||
} catch(IOException ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("DeckIO : read() error, " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
public Deck parseDeck(File f)//cast(in case read is private for a good reason)
|
||||
{
|
||||
try{return read(new BufferedReader(new FileReader(f)));}
|
||||
catch(Exception e){return null;}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
|
||||
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
|
||||
@@ -2,6 +2,8 @@
|
||||
package forge;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
@@ -342,8 +344,8 @@ public class QuestData implements NewConstants {
|
||||
}
|
||||
|
||||
public Deck ai_getDeckNewFormat(String deckName) {
|
||||
DeckIO deckIO = new NewDeckIO(ForgeProps.getFile(QUEST.DECKS), true);
|
||||
Deck aiDeck = deckIO.readDeck(deckName);
|
||||
DeckManager deckManager = new DeckManager(ForgeProps.getFile(QUEST.DECKS));
|
||||
Deck aiDeck = deckManager.readDeck(deckName);
|
||||
return aiDeck;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ package forge;
|
||||
*/
|
||||
|
||||
|
||||
import forge.deck.Deck;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package forge;
|
||||
|
||||
import forge.deck.Deck;
|
||||
|
||||
public class Run {
|
||||
public static void main(String[] args) {
|
||||
AllZone.Computer = new ComputerAI_Input(new ComputerAI_General());
|
||||
|
||||
174
src/forge/deck/Deck.java
Normal file
174
src/forge/deck/Deck.java
Normal file
@@ -0,0 +1,174 @@
|
||||
package forge.deck;
|
||||
|
||||
import forge.Card;
|
||||
import forge.Constant;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Deck implements Comparable{
|
||||
//gameType is from Constant.GameType, like Constant.GameType.Regular
|
||||
|
||||
private Map<String, String> metadata = new HashMap<String, String>();
|
||||
|
||||
private List<String> main, sideboard, mainView, sideboardView;
|
||||
|
||||
public static final String NAME = "Name";
|
||||
public static final String DECK_TYPE = "Deck Type";
|
||||
public static final String COMMENT = "Comment";
|
||||
public static final String DESCRIPTION = "Description";
|
||||
public static final String DIFFICULTY = "Difficulty";
|
||||
|
||||
|
||||
//gameType is from Constant.GameType, like Constant.GameType.Regular
|
||||
public Deck(String gameType) {
|
||||
setDeckType(gameType);
|
||||
setName("");
|
||||
|
||||
main = new ArrayList<String>();
|
||||
mainView = Collections.unmodifiableList(main);
|
||||
|
||||
sideboard = new ArrayList<String>();
|
||||
sideboardView = Collections.unmodifiableList(sideboard);
|
||||
}
|
||||
|
||||
public Deck(String deckType, List<String> main, List<String> sideboard, String name) {
|
||||
setDeckType(deckType);
|
||||
setName(name);
|
||||
|
||||
this.main = main;
|
||||
mainView = Collections.unmodifiableList(main);
|
||||
|
||||
this.sideboard = main;
|
||||
sideboardView = Collections.unmodifiableList(sideboard);
|
||||
}
|
||||
|
||||
public List<String> getMain() {
|
||||
return mainView;
|
||||
}
|
||||
|
||||
public List<String> getSideboard() {
|
||||
return sideboardView;
|
||||
}
|
||||
|
||||
public String getDeckType() {
|
||||
return metadata.get(DECK_TYPE);
|
||||
}
|
||||
|
||||
//can only call this method ONCE
|
||||
private void setDeckType(String deckType) {
|
||||
if (this.getDeckType() != null) {
|
||||
throw new IllegalStateException(
|
||||
"Deck : setDeckType() error, deck type has already been set");
|
||||
}
|
||||
|
||||
if (!Constant.GameType.GameTypes.contains(deckType)) {
|
||||
throw new RuntimeException(
|
||||
"Deck : setDeckType() error, invalid deck type - " + deckType);
|
||||
}
|
||||
|
||||
metadata.put(DECK_TYPE, deckType);
|
||||
}
|
||||
|
||||
public void setName(String s) {
|
||||
metadata.put(NAME, s);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return metadata.get(NAME);
|
||||
}//may return null
|
||||
|
||||
public void setComment(String comment) {
|
||||
metadata.put(COMMENT, comment);
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return metadata.get(COMMENT);
|
||||
|
||||
}
|
||||
|
||||
public void addMain(String cardName) {
|
||||
main.add(cardName);
|
||||
}
|
||||
|
||||
public int countMain() {
|
||||
return main.size();
|
||||
}
|
||||
|
||||
public String getMain(int index) {
|
||||
return main.get(index);
|
||||
}
|
||||
|
||||
public String removeMain(int index) {
|
||||
return main.remove(index);
|
||||
}
|
||||
|
||||
public void removeMain(Card c) {
|
||||
if (main.contains(c.getName())) {
|
||||
int i = main.indexOf(c.getName());
|
||||
main.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void addSideboard(String cardName) {
|
||||
sideboard.add(cardName);
|
||||
}
|
||||
|
||||
public int countSideboard() {
|
||||
return sideboard.size();
|
||||
}
|
||||
|
||||
public String getSideboard(int index) {
|
||||
return sideboard.get(index);
|
||||
}
|
||||
|
||||
public String removeSideboard(int index) {
|
||||
return sideboard.remove(index);
|
||||
}
|
||||
|
||||
public boolean isDraft() {
|
||||
return getDeckType().equals(Constant.GameType.Draft);
|
||||
}
|
||||
|
||||
public boolean isSealed() {
|
||||
return getDeckType().equals(Constant.GameType.Sealed);
|
||||
}
|
||||
|
||||
public boolean isRegular() {
|
||||
return getDeckType().equals(Constant.GameType.Constructed);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return getName().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
|
||||
// The setters and getters below are for Quest decks
|
||||
public void setDifficulty(String s) {
|
||||
metadata.put(DIFFICULTY, s);
|
||||
}
|
||||
|
||||
public String getDifficulty() {
|
||||
return metadata.get(DIFFICULTY);
|
||||
}
|
||||
|
||||
public void setDescription(String s) {
|
||||
metadata.put(DESCRIPTION, s);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return metadata.get(DESCRIPTION);
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
if (o instanceof Deck)
|
||||
{
|
||||
return getName().compareTo(((Deck)o).getName());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
344
src/forge/deck/DeckManager.java
Executable file
344
src/forge/deck/DeckManager.java
Executable file
@@ -0,0 +1,344 @@
|
||||
package forge.deck;
|
||||
|
||||
|
||||
import forge.Constant;
|
||||
import forge.error.ErrorViewer;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.lang.Integer.parseInt;
|
||||
import static java.lang.String.format;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
|
||||
//reads and write Deck objects
|
||||
public class DeckManager {
|
||||
private static FilenameFilter DCKFileFilter = new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".dck");
|
||||
}
|
||||
};
|
||||
private static FilenameFilter BDKFileFilter = new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".bdk");
|
||||
}
|
||||
};
|
||||
|
||||
private File deckDir;
|
||||
Map<String, Deck> deckMap;
|
||||
Map<String, Deck[]> boosterMap;
|
||||
|
||||
public DeckManager(String fileName) {
|
||||
this(new File(fileName));
|
||||
}
|
||||
|
||||
public DeckManager(File deckDir) {
|
||||
if (deckDir == null) {
|
||||
throw new IllegalArgumentException("No deck directory specified");
|
||||
}
|
||||
try {
|
||||
this.deckDir = deckDir;
|
||||
|
||||
if (deckDir.isFile()) {
|
||||
throw new IOException("Not a directory");
|
||||
}
|
||||
else {
|
||||
deckDir.mkdirs();
|
||||
if (!deckDir.isDirectory()) {
|
||||
throw new IOException("Directory can't be created");
|
||||
}
|
||||
this.deckMap = new HashMap<String, Deck>();
|
||||
this.boosterMap = new HashMap<String, Deck[]>();
|
||||
readDir();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
throw new RuntimeException("DeckManager : write() error, " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isUnique(String deckName) {
|
||||
return !deckMap.containsKey(deckName);
|
||||
}
|
||||
|
||||
public boolean isUniqueDraft(String deckName) {
|
||||
return !boosterMap.keySet().contains(deckName);
|
||||
}
|
||||
|
||||
private int findDeckIndex(String deckName) {
|
||||
int n = -1;
|
||||
for (int i = 0; i < deckMap.size(); i++) {
|
||||
if ((deckMap.get(i)).getName().equals(deckName)) {
|
||||
n = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (n == -1) {
|
||||
throw new RuntimeException("DeckManager : findDeckIndex() error, deck name not found - " + deckName);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
public void addDeck(Deck deck) {
|
||||
if (deck.getDeckType().equals(Constant.GameType.Draft)) {
|
||||
throw new RuntimeException(
|
||||
"DeckManager : addDeck() error, deck type is Draft");
|
||||
}
|
||||
|
||||
deckMap.put(deck.getName(), deck);
|
||||
}
|
||||
|
||||
public void deleteDeck(String deckName) {
|
||||
deckMap.remove(deckName);
|
||||
}
|
||||
|
||||
public Deck[] readBoosterDeck(String deckName) {
|
||||
if (!boosterMap.containsKey(deckName)) {
|
||||
throw new RuntimeException(
|
||||
"DeckManager : 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(
|
||||
"DeckManager : 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("DeckManager : checkBoosterDeck() error, invalid deck");
|
||||
}
|
||||
}//checkBoosterDeck()
|
||||
|
||||
|
||||
public Collection<Deck> getDecks() {
|
||||
return deckMap.values();
|
||||
}
|
||||
|
||||
public Map<String, Deck[]> getBoosterDecks() {
|
||||
return new HashMap<String, Deck[]>(boosterMap);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
writeFile();
|
||||
}
|
||||
|
||||
|
||||
public void readDir() {
|
||||
deckMap.clear();
|
||||
boosterMap.clear();
|
||||
|
||||
File[] files;
|
||||
|
||||
files = deckDir.listFiles(DCKFileFilter);
|
||||
for (File file : files) {
|
||||
Deck newDeck = readDeck(file);
|
||||
deckMap.put(newDeck.getName(), newDeck);
|
||||
}
|
||||
|
||||
files = deckDir.listFiles(BDKFileFilter);
|
||||
for (File file : files) {
|
||||
Deck[] d = new Deck[8];
|
||||
|
||||
for (int i = 0; i < d.length; i++) {
|
||||
d[i] = readDeck(new File(file, i + ".dck"));
|
||||
}
|
||||
|
||||
boosterMap.put(d[0].getName(), d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Deck readDeck(String fileName) {
|
||||
return readDeck(new File(fileName));
|
||||
}
|
||||
|
||||
public static Deck readDeck(File deckFile) {
|
||||
|
||||
List<String> lines = new LinkedList<String>();
|
||||
|
||||
try {
|
||||
BufferedReader r = new BufferedReader(new FileReader(deckFile));
|
||||
|
||||
String line;
|
||||
while ((line = r.readLine()) != null) {
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
r.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ListIterator<String> lineIterator = lines.listIterator();
|
||||
|
||||
String firstLine = lineIterator.next();
|
||||
|
||||
//Old text-based format
|
||||
if (!firstLine.equals("[Metadata]")) {
|
||||
lineIterator.previous();
|
||||
return readDeckOld(lineIterator);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static Deck readDeckOld(ListIterator<String> iterator) {
|
||||
|
||||
String line;
|
||||
//readDeck name
|
||||
String name = iterator.next();
|
||||
|
||||
//readDeck comments
|
||||
String comment = null;
|
||||
while ((line = iterator.next()) != null && !line.equals("[general]")) {
|
||||
if (comment == null) {
|
||||
comment = line;
|
||||
}
|
||||
else {
|
||||
comment += "\n" + line;
|
||||
}
|
||||
}
|
||||
|
||||
//readDeck deck type
|
||||
String deckType = iterator.next();
|
||||
|
||||
Deck d = new Deck(deckType);
|
||||
d.setName(name);
|
||||
d.setComment(comment);
|
||||
|
||||
//go to [main]
|
||||
while ((line = iterator.next()) != null && !line.equals("[main]")) {
|
||||
System.err.println("unexpected line: " + line);
|
||||
}
|
||||
|
||||
Pattern p = Pattern.compile("\\s*((\\d+)\\s+)?(.*?)\\s*");
|
||||
|
||||
//readDeck main deck
|
||||
while ((line = iterator.next()) != null && !line.equals("[sideboard]")) {
|
||||
Matcher m = p.matcher(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));
|
||||
}
|
||||
}
|
||||
|
||||
//readDeck sideboard
|
||||
while ((line = iterator.next()) != null && line.length() != 0) {
|
||||
Matcher m = p.matcher(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(deckDir.listFiles(DCKFileFilter)));
|
||||
|
||||
//save the files and remove them from the list
|
||||
for (Deck deck : deckMap.values()) {
|
||||
File f = new File(deckDir, deriveFileName(deck.getName()) + ".DCKFileFilter");
|
||||
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(deckDir.listFiles(BDKFileFilter)));
|
||||
|
||||
//save the files and remove them from the list
|
||||
for (Entry<String, Deck[]> e : boosterMap.entrySet()) {
|
||||
File f = new File(deckDir, 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 + ".DCKFileFilter")));
|
||||
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("DeckManager : 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 + 1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
130
src/forge/deck/DownloadDeck.java
Normal file
130
src/forge/deck/DownloadDeck.java
Normal file
@@ -0,0 +1,130 @@
|
||||
package forge.deck;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
|
||||
public class DownloadDeck {
|
||||
|
||||
|
||||
public String foundNumberCard(String rStr) {
|
||||
int temp;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < rStr.length(); i++) {
|
||||
temp = rStr.codePointAt(i);
|
||||
if (temp >= 48 && temp <= 57) {
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (rStr.codePointAt(i + 1) >= 48 && rStr.codePointAt(i + 1) <= 57) {
|
||||
return rStr.substring(i, i + 2);
|
||||
}
|
||||
else {
|
||||
return rStr.substring(i, i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public String foundNameCard(String rStr) {
|
||||
int temp;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < rStr.length(); i++) {
|
||||
temp = rStr.codePointAt(i);
|
||||
if (temp >= 48 && temp <= 57) {
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return rStr.substring(0, i - 1);
|
||||
}
|
||||
|
||||
|
||||
public String removeSpace(String rStr) {
|
||||
int temp;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < rStr.length(); i++) {
|
||||
temp = rStr.codePointAt(i);
|
||||
if (temp != 32) {
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return rStr.substring(i);
|
||||
}
|
||||
|
||||
public String removeSpaceBack(String rStr) {
|
||||
int temp;
|
||||
int i;
|
||||
|
||||
for (i = rStr.length() - 1; i > -1; i = i - 1) {
|
||||
temp = rStr.codePointAt(i);
|
||||
if (temp != 32) {
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return rStr.substring(0, i + 1);
|
||||
}
|
||||
|
||||
public String removeFoundNumberCard(String rStr, String Number) {
|
||||
int a;
|
||||
int temp;
|
||||
a = rStr.indexOf(Number);
|
||||
temp = rStr.codePointAt(a + 1);
|
||||
if (temp >= 48 && temp <= 57) {
|
||||
return rStr.substring(a + 2);
|
||||
}
|
||||
else {
|
||||
return rStr.substring(a + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String removeFoundNameCard(String rStr, String Name) {
|
||||
int a;
|
||||
a = Name.length();
|
||||
return rStr.substring(a);
|
||||
|
||||
}
|
||||
|
||||
public boolean isCardSupport(String CardName) {
|
||||
CardList all = AllZone.CardFactory.getAllCards();
|
||||
|
||||
Card gCard;
|
||||
for (int i = 0; i < all.size(); i++) {
|
||||
gCard = all.getCard(i);
|
||||
if (CardName.equalsIgnoreCase(gCard.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Card getCardDownload(Card c, String CardName) {
|
||||
CardList all = AllZone.CardFactory.getAllCards();
|
||||
|
||||
Card newCard = null;
|
||||
|
||||
for (int i = 0; i < all.size(); i++) {
|
||||
newCard = all.getCard(i);
|
||||
|
||||
if (CardName.equalsIgnoreCase(newCard.getName())) {
|
||||
return newCard;
|
||||
}
|
||||
}
|
||||
|
||||
return newCard;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
package forge.deck.generate;
|
||||
|
||||
import forge.*;
|
||||
import forge.deck.Deck;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
import forge.CardListFilter;
|
||||
import forge.CardListUtil;
|
||||
import forge.CardUtil;
|
||||
import forge.Constant;
|
||||
import forge.Deck;
|
||||
import forge.ReadBoosterPack;
|
||||
|
||||
public class GenerateDraftDeck
|
||||
{
|
||||
private static Map<String,String> map = new HashMap<String,String>();
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package forge.quest.data;
|
||||
|
||||
import forge.*;
|
||||
import forge.AllZone;
|
||||
import forge.FileUtil;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
@@ -42,9 +45,7 @@ public class QuestBattleManager {
|
||||
}
|
||||
|
||||
public static Deck getAIDeckNewFormat(String deckName) {
|
||||
DeckIO deckIO = new NewDeckIO(ForgeProps.getFile(NewConstants.QUEST.DECKS), true);
|
||||
Deck aiDeck = deckIO.readDeck(deckName);
|
||||
return aiDeck;
|
||||
return DeckManager.readDeck(deckName);
|
||||
}
|
||||
|
||||
public static List<String> getAIDeckNames() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge.quest.data;
|
||||
|
||||
import forge.*;
|
||||
import forge.deck.Deck;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
@@ -2,7 +2,7 @@ package forge.quest.data;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.mapper.MapperWrapper;
|
||||
import forge.Deck;
|
||||
import forge.deck.Deck;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
@@ -2,6 +2,7 @@ package forge.quest.gui.main;
|
||||
|
||||
|
||||
import forge.*;
|
||||
import forge.deck.Deck;
|
||||
import forge.gui.ForgeFontConstants;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.quest.data.QuestBattleManager;
|
||||
|
||||
Reference in New Issue
Block a user