spjspj - Add the option of having a .dck file as a cube

This commit is contained in:
spjspj 2016-07-04 00:20:31 +10:00
parent 548b05ba74
commit 26d38f0773
6 changed files with 153 additions and 13 deletions

View file

@ -31,10 +31,10 @@
*
* Created on Jan 28, 2011, 12:15:56 PM
*/
package mage.client.dialog;
import java.awt.Component;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -44,9 +44,11 @@ import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.SpinnerNumberModel;
import javax.swing.filechooser.FileFilter;
import mage.cards.decks.importer.DeckImporterUtil;
import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository;
@ -66,7 +68,6 @@ import mage.view.TableView;
import mage.view.TournamentTypeView;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
@ -88,7 +89,7 @@ public class NewTournamentDialog extends MageDialog {
private final int CONSTRUCTION_TIME_MAX = 30;
private boolean isRandom = false;
private boolean isRichMan = false;
private String cubeFromDeckFilename = "";
private boolean automaticChange = false;
/** Creates new form NewTournamentDialog */
@ -557,6 +558,9 @@ public class NewTournamentDialog extends MageDialog {
tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom());
if (tournamentType.isCubeBooster()) {
tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString());
if (!(cubeFromDeckFilename.equals(""))) {
tOptions.getLimitedOptions().setCubeFromDeckFilename(cubeFromDeckFilename);
}
} else if (tournamentType.isRandom() || tournamentType.isRichMan()) {
this.isRandom = tournamentType.isRandom();
this.isRichMan = tournamentType.isRichMan();
@ -649,8 +653,32 @@ public class NewTournamentDialog extends MageDialog {
// TODO add your handling code here:
}//GEN-LAST:event_spnNumWinsnumPlayersChanged
private JFileChooser fcSelectDeck = null;
protected String playerLoadDeck() {
if (fcSelectDeck == null) {
fcSelectDeck = new JFileChooser();
fcSelectDeck.setAcceptAllFileFilterUsed(false);
fcSelectDeck.addChoosableFileFilter(new DeckFilter());
}
String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", "");
if (!lastFolder.isEmpty()) {
fcSelectDeck.setCurrentDirectory(new File(lastFolder));
}
int ret = fcSelectDeck.showDialog(this, "Select Deck");
if (ret == JFileChooser.APPROVE_OPTION) {
File file = fcSelectDeck.getSelectedFile();
return (file.getPath());
}
return "";
}
private void cbDraftCubeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDraftCubeActionPerformed
// TODO add your handling code here:
cubeFromDeckFilename = "";
if (cbDraftCube.getSelectedItem().toString().equals("Cube From Deck")) {
cubeFromDeckFilename = playerLoadDeck();
}
}//GEN-LAST:event_cbDraftCubeActionPerformed
private void cbDraftTimingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDraftTimingActionPerformed
@ -676,6 +704,7 @@ public class NewTournamentDialog extends MageDialog {
// this.cbRange.setEnabled(gameType.isUseRange());
createPlayers((Integer) spnNumPlayers.getValue() - 1);
}
private void setTournamentOptions(int numPlayers) {
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
activatePanelElements(tournamentType);
@ -709,6 +738,7 @@ public class NewTournamentDialog extends MageDialog {
this.revalidate();
this.repaint();
}
/**
* Sets elements of the panel to visible or not visible
*
@ -911,7 +941,6 @@ public class NewTournamentDialog extends MageDialog {
automaticChange = false;
}
/**
* set the tournament settings from java prefs
*/
@ -1053,7 +1082,6 @@ public class NewTournamentDialog extends MageDialog {
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_RATED, (tOptions.getMatchOptions().isRated() ? "Yes" : "No"));
}
public TableView getTable() {
return table;
}
@ -1107,3 +1135,27 @@ public class NewTournamentDialog extends MageDialog {
// End of variables declaration//GEN-END:variables
}
class DeckFilter extends FileFilter {
@Override
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1) {
ext = s.substring(i + 1).toLowerCase();
}
return (ext == null) ? false : ext.equals("dck");
}
@Override
public String getDescription() {
return "Deck Files";
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.tournament.cubes;
import mage.cards.decks.DeckCardInfo;
import mage.cards.decks.DeckCardLists;
import mage.cards.decks.importer.DeckImporterUtil;
import mage.game.draft.DraftCube.CardIdentity;
import mage.game.draft.DraftCube;
/**
*
* @author spjspj
*/
public class CubeFromDeck extends DraftCube {
public CubeFromDeck(String chosenDckFile) {
super("Cube From Deck");
DeckCardLists cards = DeckImporterUtil.importDeck(chosenDckFile);
if (cards != null) {
for (DeckCardInfo card : cards.getCards()) {
cubeCards.add(new CardIdentity(card.getCardName(), card.getSetCode()));
}
}
}
}

View file

@ -110,6 +110,7 @@
<draftCube name="MTGO Vintage Cube 2016" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.VintageCube2016"/>
<draftCube name="The Peasant's Toolbox (800 cards)" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.PeasantsToolboxCube"/>
<draftCube name="www.MTGCube.com (502 cards)" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.MTGCube"/>
<draftCube name="Cube From Deck" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.CubeFromDeck"/>
</draftCubes>
<deckTypes>
<deckType name="Constructed - Standard" jar="mage-deck-constructed.jar" className="mage.deck.Standard"/>

View file

@ -67,6 +67,22 @@ public class CubeFactory {
return draftCube;
}
public DraftCube createDeckDraftCube(String draftCubeName, String chosenDckFile) {
DraftCube draftCube;
Constructor<?> con;
try {
con = draftCubes.get(draftCubeName).getConstructor(new Class[]{String.class});
draftCube = (DraftCube)con.newInstance(new Object[] {chosenDckFile});
} catch (Exception ex) {
logger.fatal("CubeFactory error", ex);
return null;
}
logger.debug("Draft cube created: " + draftCube.getName());
return draftCube;
}
public Set<String> getDraftCubes() {
return draftCubes.keySet();
}

View file

@ -35,6 +35,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import mage.cards.Sets;
import mage.game.draft.DraftCube;
import mage.game.tournament.Tournament;
import mage.game.tournament.TournamentOptions;
import mage.game.tournament.TournamentType;
@ -78,7 +79,14 @@ public class TournamentFactory {
}
tournament.getOptions().getLimitedOptions().setNumberBoosters(tournament.getTournamentType().getNumBoosters());
if (tournament.getTournamentType().isCubeBooster()) {
tournament.getOptions().getLimitedOptions().setDraftCube(CubeFactory.getInstance().createDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName()));
DraftCube draftCube = null;
if (tournament.getOptions().getLimitedOptions().getCubeFromDeckFilename().length() != 0) {
draftCube = CubeFactory.getInstance().createDeckDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName(), tournament.getOptions().getLimitedOptions().getCubeFromDeckFilename());
} else {
draftCube = CubeFactory.getInstance().createDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName());
}
tournament.getOptions().getLimitedOptions().setDraftCube(draftCube);
tournament.setBoosterInfo(tournament.getOptions().getLimitedOptions().getDraftCubeName());
} else if (tournament.getTournamentType().isRandom()) {
StringBuilder rv = new StringBuilder( "Random Draft using sets: ");

View file

@ -45,6 +45,7 @@ public class LimitedOptions implements Serializable {
protected DraftCube draftCube;
protected int numberBoosters;
protected boolean isRandom;
protected String cubeFromDeckFilename = "";
public List<String> getSetCodes() {
return sets;
@ -66,6 +67,14 @@ public class LimitedOptions implements Serializable {
this.draftCubeName = draftCubeName;
}
public void setCubeFromDeckFilename(String cubeFromDeckFilename) {
this.cubeFromDeckFilename = cubeFromDeckFilename;
}
public String getCubeFromDeckFilename() {
return cubeFromDeckFilename;
}
public DraftCube getDraftCube() {
return draftCube;
}
@ -88,4 +97,5 @@ public class LimitedOptions implements Serializable {
public void setIsRandom(boolean isRandom){
this.isRandom = isRandom;
}
}