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