mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Renamed DeckManager methods to be more accurate. Replaced Deck re-reads with HashMap lookups.
This commit is contained in:
@@ -1,52 +1,54 @@
|
||||
package forge;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckManager;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
public class BoosterGenerator {
|
||||
private CardList commons = new CardList();
|
||||
private CardList uncommons = new CardList();
|
||||
private CardList rares = new CardList();
|
||||
private CardList mythics = new CardList();
|
||||
private CardList specials = new CardList();
|
||||
|
||||
|
||||
private int iCommons = 0;
|
||||
private int iUncommons = 0;
|
||||
private int iRares = 0;
|
||||
private int iMythics = 0;
|
||||
private int iSpecials = 0;
|
||||
|
||||
|
||||
private int numCommons = 11;
|
||||
private int numUncommons = 3;
|
||||
private int numRares = 1;
|
||||
private int numMythics = 0;
|
||||
private int numSpecials = 0;
|
||||
|
||||
|
||||
private Random r = new Random();
|
||||
|
||||
|
||||
public BoosterGenerator() {
|
||||
CardList tList = AllZone.CardFactory.getAllCards();
|
||||
for (int i=0; i<tList.size(); i++) {
|
||||
Card c = tList.get(i);
|
||||
SetInfo si = SetInfoUtil.getSetInfo_Code(c.getSets(), SetInfoUtil.getMostRecentSet(c.getSets()));
|
||||
|
||||
|
||||
addToRarity(c, si);
|
||||
}
|
||||
|
||||
|
||||
shuffleAll();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public BoosterGenerator(String DeckFile, int nCommons, int nUncommons, int nRares, int nMythics, int nSpecials, boolean ignoreRarity) {
|
||||
NewDeckIO dio = new NewDeckIO(ForgeProps.getFile(NewConstants.NEW_DECKS));
|
||||
Deck dPool= dio.readDeck(DeckFile);
|
||||
DeckManager dio = new DeckManager(ForgeProps.getFile(NewConstants.NEW_DECKS));
|
||||
Deck dPool= dio.getDeck(DeckFile);
|
||||
CardList cList = new CardList();
|
||||
List<String> tList = dPool.getMain();
|
||||
|
||||
|
||||
for (int i=0; i<tList.size(); i++) {
|
||||
String cardName = dPool.getMain(i);
|
||||
String setCode = "";
|
||||
@@ -56,9 +58,9 @@ public class BoosterGenerator {
|
||||
cardName = s[0];
|
||||
setCode = s[1];
|
||||
}
|
||||
|
||||
|
||||
Card c = AllZone.CardFactory.getCard(cardName, AllZone.HumanPlayer);
|
||||
|
||||
|
||||
if (!setCode.equals(""))
|
||||
c.setCurSetCode(setCode);
|
||||
else if ((c.getSets().size() > 0)) // && card.getCurSetCode().equals(""))
|
||||
@@ -67,67 +69,70 @@ public class BoosterGenerator {
|
||||
cList.add(c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (int i=0; i<cList.size();i++) {
|
||||
Card c = cList.get(i);
|
||||
SetInfo si = null;
|
||||
if (c.getCurSetCode().equals(""))
|
||||
si = SetInfoUtil.getSetInfo_Code(c.getSets(), SetInfoUtil.getMostRecentSet(c.getSets()));
|
||||
else
|
||||
si = SetInfoUtil.getSetInfo_Code(c.getSets(), c.getCurSetCode());
|
||||
|
||||
si = SetInfoUtil.getSetInfo_Code(c.getSets(), c.getCurSetCode());
|
||||
|
||||
if (ignoreRarity)
|
||||
commons.add(c);
|
||||
else
|
||||
addToRarity(c, si);
|
||||
}
|
||||
|
||||
|
||||
shuffleAll();
|
||||
|
||||
|
||||
numCommons = nCommons;
|
||||
numUncommons = nUncommons;
|
||||
numRares = nRares;
|
||||
numMythics = nMythics;
|
||||
numSpecials = nSpecials;
|
||||
}
|
||||
|
||||
|
||||
public BoosterGenerator(final String SetCode) {
|
||||
CardList tList = AllZone.CardFactory.getAllCards();
|
||||
for (int i=0; i<tList.size(); i++) {
|
||||
Card c = tList.get(i);
|
||||
SetInfo si = SetInfoUtil.getSetInfo_Code(c.getSets(), SetCode);
|
||||
|
||||
|
||||
if (si != null) {
|
||||
c.setCurSetCode(SetCode);
|
||||
|
||||
|
||||
Random r = new Random();
|
||||
int n = si.PicCount;
|
||||
if (n > 1)
|
||||
c.setRandomPicture(r.nextInt(n-1) + 1);
|
||||
|
||||
|
||||
addToRarity(c, si);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
shuffleAll();
|
||||
|
||||
|
||||
ArrayList<String> bpData = FileUtil.readFile("res/boosterdata/" + SetCode + ".pack");
|
||||
|
||||
for (int i=0; i<bpData.size(); i++) {
|
||||
String line = bpData.get(i);
|
||||
|
||||
if (line.startsWith("Commons:"))
|
||||
numCommons = Integer.parseInt(line.substring(8));
|
||||
else if (line.startsWith("Uncommons:"))
|
||||
numUncommons = Integer.parseInt(line.substring(10));
|
||||
else if (line.startsWith("Rares:"))
|
||||
numRares = Integer.parseInt(line.substring(6));
|
||||
else if (line.startsWith("Mythics:"))
|
||||
numMythics = Integer.parseInt(line.substring(8));
|
||||
else if (line.startsWith("Specials:"))
|
||||
numSpecials = Integer.parseInt(line.substring(9));
|
||||
|
||||
}
|
||||
|
||||
for (String line : bpData) {
|
||||
if (line.startsWith("Commons:")) {
|
||||
numCommons = Integer.parseInt(line.substring(8));
|
||||
}
|
||||
else if (line.startsWith("Uncommons:")) {
|
||||
numUncommons = Integer.parseInt(line.substring(10));
|
||||
}
|
||||
else if (line.startsWith("Rares:")) {
|
||||
numRares = Integer.parseInt(line.substring(6));
|
||||
}
|
||||
else if (line.startsWith("Mythics:")) {
|
||||
numMythics = Integer.parseInt(line.substring(8));
|
||||
}
|
||||
else if (line.startsWith("Specials:")) {
|
||||
numSpecials = Integer.parseInt(line.substring(9));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
System.out.println("numCommons: " + numCommons);
|
||||
System.out.println("numUncommons: " + numUncommons);
|
||||
@@ -136,7 +141,7 @@ public class BoosterGenerator {
|
||||
System.out.println("numSpecials: " + numSpecials);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void addToRarity(Card c, SetInfo si) {
|
||||
if (si != null) {
|
||||
if (si.Rarity.equals("Common"))
|
||||
@@ -149,99 +154,99 @@ public class BoosterGenerator {
|
||||
mythics.add(c);
|
||||
else if (si.Rarity.equals("Special"))
|
||||
specials.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void shuffleAll() {
|
||||
|
||||
|
||||
if (commons.size() > 0)
|
||||
commons.shuffle();
|
||||
|
||||
|
||||
System.out.println("commons.size: " + commons.size());
|
||||
|
||||
|
||||
if (uncommons.size() > 0)
|
||||
uncommons.shuffle();
|
||||
|
||||
|
||||
System.out.println("uncommons.size: " + uncommons.size());
|
||||
|
||||
|
||||
if (rares.size() > 0)
|
||||
rares.shuffle();
|
||||
|
||||
|
||||
System.out.println("rares.size: " + rares.size());
|
||||
|
||||
|
||||
if (mythics.size() > 0)
|
||||
mythics.shuffle();
|
||||
|
||||
|
||||
System.out.println("mythics.size: " + mythics.size());
|
||||
|
||||
|
||||
if (specials.size() > 0)
|
||||
specials.shuffle();
|
||||
|
||||
|
||||
System.out.println("specials.size: " + specials.size());
|
||||
}
|
||||
|
||||
|
||||
public CardList getBoosterPack() {
|
||||
CardList temp = new CardList();
|
||||
|
||||
|
||||
int i = 0;
|
||||
|
||||
|
||||
if (commons.size() > numCommons) {
|
||||
for (i=0; i<numCommons; i++) {
|
||||
if (iCommons >= commons.size())
|
||||
iCommons = 0;
|
||||
|
||||
|
||||
temp.add(commons.get(iCommons++));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (uncommons.size() > numUncommons) {
|
||||
for (i=0; i<numUncommons; i++) {
|
||||
if (iUncommons >= uncommons.size())
|
||||
iUncommons = 0;
|
||||
|
||||
|
||||
temp.add(uncommons.get(iUncommons++));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i=0; i<numRares; i++) {
|
||||
if (numMythics > 0) {
|
||||
if (mythics.size() > numMythics) {
|
||||
if (r.nextInt(8) <= 1) {
|
||||
if (iMythics >= mythics.size())
|
||||
iMythics = 0;
|
||||
|
||||
|
||||
temp.add(mythics.get(iMythics++));
|
||||
}
|
||||
else {
|
||||
if (iRares >= rares.size())
|
||||
iRares = 0;
|
||||
|
||||
|
||||
temp.add(rares.get(iRares++));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (rares.size() > numRares) {
|
||||
if (iRares >= rares.size())
|
||||
iRares = 0;
|
||||
|
||||
|
||||
temp.add(rares.get(iRares++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (specials.size() > numSpecials) {
|
||||
for (i=0; i<numSpecials; i ++) {
|
||||
if (iSpecials >= specials.size())
|
||||
iSpecials = 0;
|
||||
|
||||
|
||||
temp.add(specials.get(iSpecials++));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
public int getBoosterPackSize() {
|
||||
return numCommons + numUncommons + numRares + numSpecials;
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ public class Gui_BoosterDraft extends JFrame implements CardContainer, NewConsta
|
||||
human, computer[0], computer[1], computer[2], computer[3], computer[4], computer[5], computer[6]};
|
||||
|
||||
DeckManager deckManager = new DeckManager(ForgeProps.getFile(NEW_DECKS));
|
||||
deckManager.writeBoosterDeck(all);
|
||||
deckManager.addBoosterDeck(all);
|
||||
|
||||
//write file
|
||||
deckManager.close();
|
||||
|
||||
@@ -51,7 +51,6 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
|
||||
private final DeckManager deckManager = new DeckManager(ForgeProps.getFile(NEW_DECKS));
|
||||
//with the new IO, there's no reason to use different instances
|
||||
private final DeckManager boosterDeckManager = deckManager;
|
||||
|
||||
private boolean isDeckSaved;
|
||||
|
||||
@@ -344,7 +343,7 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
currentGameType = Constant.GameType.Draft;
|
||||
|
||||
//move all cards from deck main and sideboard to CardList
|
||||
Deck deck = boosterDeckManager.readBoosterDeck(currentDeckName)[0];
|
||||
Deck deck = deckManager.readBoosterDeck(currentDeckName)[0];
|
||||
setDeckData("", false);
|
||||
|
||||
CardList top = new CardList();
|
||||
@@ -637,7 +636,7 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
//and the other 7 are the computer's deck
|
||||
if (currentGameType.equals(Constant.GameType.Draft)) {
|
||||
//read all draft decks
|
||||
Deck d[] = boosterDeckManager.readBoosterDeck(currentDeckName);
|
||||
Deck d[] = deckManager.readBoosterDeck(currentDeckName);
|
||||
|
||||
//replace your deck
|
||||
d[0] = deck;
|
||||
@@ -807,7 +806,7 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
currentGameType = Constant.GameType.Constructed;
|
||||
newDraftItem.setEnabled(false);
|
||||
|
||||
Deck deck = DeckManager.readDeck(name);
|
||||
Deck deck = deckManager.getDeck(name);
|
||||
showConstructedDeck(deck);
|
||||
}//open constructed
|
||||
|
||||
@@ -857,7 +856,7 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
currentGameType = Constant.GameType.Sealed;
|
||||
newDraftItem.setEnabled(false);
|
||||
|
||||
Deck deck = deckManager.readDeck(name);
|
||||
Deck deck = deckManager.getDeck(name);
|
||||
showSealedDeck(deck);
|
||||
}//open sealed
|
||||
|
||||
@@ -907,7 +906,7 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
currentGameType = Constant.GameType.Draft;
|
||||
newDraftItem.setEnabled(true);
|
||||
|
||||
Deck deck = boosterDeckManager.readBoosterDeck(name)[0];
|
||||
Deck deck = deckManager.readBoosterDeck(name)[0];
|
||||
showDraftDeck(deck);
|
||||
}//open draft
|
||||
|
||||
@@ -954,9 +953,9 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
else if (currentGameType.equals(Constant.GameType.Draft)) {
|
||||
setDeckData(currentDeckName, true);
|
||||
//write booster deck
|
||||
Deck[] all = boosterDeckManager.readBoosterDeck(currentDeckName);
|
||||
Deck[] all = deckManager.readBoosterDeck(currentDeckName);
|
||||
all[0] = getDeck();
|
||||
boosterDeckManager.writeBoosterDeck(all);
|
||||
deckManager.addBoosterDeck(all);
|
||||
}
|
||||
else//constructed or sealed
|
||||
{
|
||||
@@ -978,7 +977,7 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
}
|
||||
else if (currentGameType.equals(Constant.GameType.Draft)) {
|
||||
//MUST copy array
|
||||
Deck[] read = boosterDeckManager.readBoosterDeck(currentDeckName);
|
||||
Deck[] read = deckManager.readBoosterDeck(currentDeckName);
|
||||
Deck[] all = new Deck[read.length];
|
||||
|
||||
System.arraycopy(read, 0, all, 0, read.length);
|
||||
@@ -986,7 +985,7 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
setDeckData(name, true);
|
||||
|
||||
all[0] = getDeck();
|
||||
boosterDeckManager.writeBoosterDeck(all);
|
||||
deckManager.addBoosterDeck(all);
|
||||
}
|
||||
else//constructed and sealed
|
||||
{
|
||||
@@ -1011,7 +1010,7 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
}
|
||||
|
||||
if (currentGameType.equals(Constant.GameType.Draft)) {
|
||||
boosterDeckManager.deleteBoosterDeck(currentDeckName);
|
||||
deckManager.deleteBoosterDeck(currentDeckName);
|
||||
}
|
||||
else {
|
||||
deckManager.deleteDeck(currentDeckName);
|
||||
@@ -1030,7 +1029,6 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
// save();
|
||||
|
||||
deckManager.close();
|
||||
boosterDeckManager.close();
|
||||
exitCommand.execute();
|
||||
}//close
|
||||
|
||||
@@ -1120,7 +1118,7 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
|
||||
//only get decks according to the Gui_NewGame screen option
|
||||
if (deckType.equals(Constant.GameType.Draft)) {
|
||||
|
||||
for (String s : boosterDeckManager.getBoosterDecks().keySet()) {
|
||||
for (String s : deckManager.getBoosterDecks().keySet()) {
|
||||
list.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
|
||||
private final DeckManager deckManager = new DeckManager(ForgeProps.getFile(NEW_DECKS));
|
||||
//with the new IO, there's no reason to use different instances
|
||||
private final DeckManager boosterDeckManager = deckManager;
|
||||
private List<Deck> allDecks;
|
||||
private static Gui_DeckEditor editor;
|
||||
|
||||
@@ -509,7 +508,8 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
String human = humanComboBox.getSelectedItem().toString();
|
||||
|
||||
String computer = null;
|
||||
if(computerComboBox.getSelectedItem() != null) computer = computerComboBox.getSelectedItem().toString();
|
||||
if(computerComboBox.getSelectedItem() != null)
|
||||
computer = computerComboBox.getSelectedItem().toString();
|
||||
|
||||
if(draftRadioButton.isSelected()) {
|
||||
if(human.equals("New Draft")) {
|
||||
@@ -538,7 +538,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
return;
|
||||
} else//load old draft
|
||||
{
|
||||
Deck[] deck = boosterDeckManager.readBoosterDeck(human);
|
||||
Deck[] deck = deckManager.readBoosterDeck(human);
|
||||
int index = Integer.parseInt(computer);
|
||||
|
||||
Constant.Runtime.HumanDeck[0] = deck[0];
|
||||
@@ -576,10 +576,11 @@ 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] = deckManager.readDeck(human);
|
||||
Constant.Runtime.HumanDeck[0] = deckManager.getDeck(human);
|
||||
}
|
||||
|
||||
|
||||
|
||||
assert computer != null;
|
||||
boolean computerGenerate = computer.equals("Generate Deck");
|
||||
/* boolean computerGenerateMulti3 = computer.equals("Generate 3-Color Deck");
|
||||
boolean computerGenerateMulti5 = computer.equals("Generate 5-Color Gold Deck");
|
||||
@@ -603,7 +604,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] = deckManager.readDeck(computer);
|
||||
Constant.Runtime.ComputerDeck[0] = deckManager.getDeck(computer);
|
||||
}
|
||||
}// else
|
||||
|
||||
@@ -738,19 +739,20 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
colors.add("red");
|
||||
colors.add("green");
|
||||
|
||||
Object c1 = null, c2 = null;
|
||||
if (p.equals("H"))
|
||||
String c1;
|
||||
String c2;
|
||||
if (p.equals("H"))
|
||||
{
|
||||
c1 = GuiUtils.getChoice("Select first color.", colors.toArray());
|
||||
c1 = GuiUtils.getChoice("Select first color.", colors.toArray()).toString();
|
||||
|
||||
if (c1.toString().equals("Random"))
|
||||
if (c1.equals("Random"))
|
||||
c1 = colors.get(r.nextInt(colors.size() - 1) + 1);
|
||||
|
||||
colors.remove(c1);
|
||||
|
||||
c2 = GuiUtils.getChoice("Select second color.", colors.toArray());
|
||||
c2 = GuiUtils.getChoice("Select second color.", colors.toArray()).toString();
|
||||
|
||||
if (c2.toString().equals("Random"))
|
||||
if (c2.equals("Random"))
|
||||
c2 = colors.get(r.nextInt(colors.size() - 1) + 1);
|
||||
}
|
||||
else //if (p.equals("C"))
|
||||
@@ -759,7 +761,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
colors.remove(c1);
|
||||
c2 = colors.get(r.nextInt(colors.size() - 1) + 1);
|
||||
}
|
||||
Generate2ColorDeck gen = new Generate2ColorDeck(c1.toString(), c2.toString());
|
||||
Generate2ColorDeck gen = new Generate2ColorDeck(c1, c2);
|
||||
CardList d = gen.get2ColorDeck(60);
|
||||
|
||||
Deck deck = new Deck(Constant.GameType.Constructed);
|
||||
@@ -783,25 +785,27 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
colors.add("red");
|
||||
colors.add("green");
|
||||
|
||||
Object c1 = null, c2 = null, c3 = null;
|
||||
if (p.equals("H"))
|
||||
String c1;
|
||||
String c2;
|
||||
String c3;
|
||||
if (p.equals("H"))
|
||||
{
|
||||
c1 = GuiUtils.getChoice("Select first color.", colors.toArray());
|
||||
c1 = GuiUtils.getChoice("Select first color.", colors.toArray()).toString();
|
||||
|
||||
if (c1.toString().equals("Random"))
|
||||
if (c1.equals("Random"))
|
||||
c1 = colors.get(r.nextInt(colors.size() - 1) + 1);
|
||||
|
||||
colors.remove(c1);
|
||||
|
||||
c2 = GuiUtils.getChoice("Select second color.", colors.toArray());
|
||||
c2 = GuiUtils.getChoice("Select second color.", colors.toArray()).toString();
|
||||
|
||||
if (c2.toString().equals("Random"))
|
||||
if (c2.equals("Random"))
|
||||
c2 = colors.get(r.nextInt(colors.size() - 1) + 1);
|
||||
|
||||
colors.remove(c2);
|
||||
|
||||
c3 = GuiUtils.getChoice("Select third color.", colors.toArray());
|
||||
if (c3.toString().equals("Random"))
|
||||
c3 = GuiUtils.getChoice("Select third color.", colors.toArray()).toString();
|
||||
if (c3.equals("Random"))
|
||||
c3 = colors.get(r.nextInt(colors.size() - 1) + 1);
|
||||
|
||||
}
|
||||
@@ -813,7 +817,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
colors.remove(c2);
|
||||
c3 = colors.get(r.nextInt(colors.size() - 1) + 1);
|
||||
}
|
||||
Generate3ColorDeck gen = new Generate3ColorDeck(c1.toString(), c2.toString(), c3.toString());
|
||||
Generate3ColorDeck gen = new Generate3ColorDeck(c1, c2, c3);
|
||||
CardList d = gen.get3ColorDeck(60);
|
||||
|
||||
Deck deck = new Deck(Constant.GameType.Constructed);
|
||||
@@ -848,12 +852,11 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
computerComboBox.addItem("Random");
|
||||
}
|
||||
|
||||
Deck d;
|
||||
for(int i = 0; i < allDecks.size(); i++) {
|
||||
d = allDecks.get(i);
|
||||
if(d.getDeckType().equals(Constant.Runtime.GameType[0])) {
|
||||
humanComboBox.addItem(d.getName());
|
||||
computerComboBox.addItem(d.getName());
|
||||
|
||||
for (Deck allDeck : allDecks) {
|
||||
if (allDeck.getDeckType().equals(Constant.Runtime.GameType[0])) {
|
||||
humanComboBox.addItem(allDeck.getName());
|
||||
computerComboBox.addItem(allDeck.getName());
|
||||
}
|
||||
}//for
|
||||
|
||||
@@ -869,9 +872,12 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
ArrayList<Deck> list = new ArrayList<Deck>();
|
||||
|
||||
Deck d;
|
||||
for(int i = 0; i < allDecks.size(); i++) {
|
||||
d = allDecks.get(i);
|
||||
if(d.getDeckType().equals(gameType)) list.add(d);
|
||||
for (Deck allDeck : allDecks) {
|
||||
d = allDeck;
|
||||
|
||||
if (d.getDeckType().equals(gameType)) {
|
||||
list.add(d);
|
||||
}
|
||||
}//for
|
||||
|
||||
//convert ArrayList to Deck[]
|
||||
@@ -887,10 +893,12 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
computerComboBox.removeAllItems();
|
||||
|
||||
humanComboBox.addItem("New Draft");
|
||||
Object[] key = boosterDeckManager.getBoosterDecks().keySet().toArray();
|
||||
Object[] key = deckManager.getBoosterDecks().keySet().toArray();
|
||||
Arrays.sort(key);
|
||||
for(int i = 0; i < key.length; i++)
|
||||
humanComboBox.addItem(key[i]);
|
||||
|
||||
for (Object aKey : key) {
|
||||
humanComboBox.addItem(aKey);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 7; i++)
|
||||
computerComboBox.addItem("" + (i + 1));
|
||||
@@ -913,8 +921,9 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LookAndFeelInfo[] info = UIManager.getInstalledLookAndFeels();
|
||||
HashMap<String, String> LAFMap = new HashMap<String, String>();
|
||||
for(int i = 0; i < info.length; i++)
|
||||
LAFMap.put(info[i].getName(), info[i].getClassName());
|
||||
for (LookAndFeelInfo anInfo : info) {
|
||||
LAFMap.put(anInfo.getName(), anInfo.getClassName());
|
||||
}
|
||||
|
||||
//add Substance LAFs:
|
||||
LAFMap.put("Autumn", "org.jvnet.substance.skin.SubstanceAutumnLookAndFeel");
|
||||
@@ -948,10 +957,9 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA
|
||||
|
||||
String[] keys = new String[LAFMap.size()];
|
||||
int count = 0;
|
||||
Iterator<String> iter = LAFMap.keySet().iterator();
|
||||
while(iter.hasNext()) {
|
||||
String s = iter.next();
|
||||
keys[count++] = s;
|
||||
|
||||
for (String s1 : LAFMap.keySet()) {
|
||||
keys[count++] = s1;
|
||||
}
|
||||
Arrays.sort(keys);
|
||||
|
||||
|
||||
@@ -345,8 +345,7 @@ public class QuestData implements NewConstants {
|
||||
|
||||
public Deck ai_getDeckNewFormat(String deckName) {
|
||||
DeckManager deckManager = new DeckManager(ForgeProps.getFile(QUEST.DECKS));
|
||||
Deck aiDeck = deckManager.readDeck(deckName);
|
||||
return aiDeck;
|
||||
return deckManager.getDeck(deckName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,10 @@ public class Deck implements Comparable{
|
||||
|
||||
private Map<String, String> metadata = new HashMap<String, String>();
|
||||
|
||||
private List<String> main, sideboard, mainView, sideboardView;
|
||||
private List<String> main;
|
||||
private List<String> sideboard;
|
||||
private transient List<String> mainView;
|
||||
private transient List<String> sideboardView;
|
||||
|
||||
public static final String NAME = "Name";
|
||||
public static final String DECK_TYPE = "Deck Type";
|
||||
|
||||
@@ -17,17 +17,19 @@ 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 static FilenameFilter DCKFileFilter = new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".dck");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private File deckDir;
|
||||
Map<String, Deck> deckMap;
|
||||
Map<String, Deck[]> boosterMap;
|
||||
@@ -70,21 +72,6 @@ public class DeckManager {
|
||||
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(
|
||||
@@ -107,11 +94,11 @@ public class DeckManager {
|
||||
return boosterMap.get(deckName);
|
||||
}
|
||||
|
||||
public void writeBoosterDeck(Deck[] deck) {
|
||||
public void addBoosterDeck(Deck[] deck) {
|
||||
checkBoosterDeck(deck);
|
||||
|
||||
boosterMap.put(deck[0].toString(), deck);
|
||||
}//writeBoosterDeck()
|
||||
}
|
||||
|
||||
public void deleteBoosterDeck(String deckName) {
|
||||
if (!boosterMap.containsKey(deckName)) {
|
||||
@@ -127,7 +114,7 @@ public class DeckManager {
|
||||
|| (!deck[0].getDeckType().equals(Constant.GameType.Draft))) {
|
||||
throw new RuntimeException("DeckManager : checkBoosterDeck() error, invalid deck");
|
||||
}
|
||||
}//checkBoosterDeck()
|
||||
}
|
||||
|
||||
|
||||
public Collection<Deck> getDecks() {
|
||||
@@ -167,12 +154,7 @@ public class DeckManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Deck readDeck(String fileName) {
|
||||
return readDeck(new File(fileName));
|
||||
}
|
||||
|
||||
public static Deck readDeck(File deckFile) {
|
||||
private Deck readDeck(File deckFile) {
|
||||
|
||||
List<String> lines = new LinkedList<String>();
|
||||
|
||||
@@ -343,4 +325,8 @@ public class DeckManager {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Deck getDeck(String deckName) {
|
||||
return deckMap.get(deckName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class QuestBattleManager {
|
||||
}
|
||||
|
||||
public static Deck getAIDeckNewFormat(String deckName) {
|
||||
return DeckManager.readDeck(deckName);
|
||||
return (new DeckManager(ForgeProps.getFile(NewConstants.QUEST.DECKS))).getDeck(deckName);
|
||||
}
|
||||
|
||||
public static List<String> getAIDeckNames() {
|
||||
|
||||
Reference in New Issue
Block a user