deck generators are dynamically loaded from definitions in deckgenerators.txt and generator/*.java. Added goblin deck generator

master
wait321 2011-10-08 11:10:07 -07:00
parent 8fd7c417be
commit ed8dc2efc7
5 changed files with 44 additions and 18 deletions

View File

@ -2,6 +2,7 @@ package magic;
import magic.data.CardDefinitions;
import magic.data.CubeDefinitions;
import magic.data.DeckGenerators;
import magic.data.DeckUtils;
import magic.data.KeywordDefinitions;
import magic.ui.MagicFrame;
@ -74,6 +75,7 @@ public class MagicMain {
CardDefinitions.getInstance().loadCardDefinitions();
CubeDefinitions.getInstance().loadCubeDefinitions();
KeywordDefinitions.getInstance().loadKeywordDefinitions();
DeckGenerators.getInstance().loadDeckGenerators();
}
private static void initialize() {

View File

@ -103,8 +103,9 @@ public class TournamentConfig {
return new MagicPlayerProfile(MagicColor.getRandomColors(2));
} else if (ANY_ONE.equals(colorText)) {
return new MagicPlayerProfile(MagicColor.getRandomColors(1));
} else if (colorText.equals("Knight")) {
return new MagicPlayerProfile("", "KnightDeckGenerator");
} else if (DeckGenerators.getInstance().getGeneratorNames().contains(colorText)) {
// custom deck generator
return new MagicPlayerProfile("", colorText);
}
return new MagicPlayerProfile(colorText);
}

View File

@ -1,6 +1,7 @@
package magic.model;
import magic.data.CardDefinitions;
import magic.data.DeckGenerators;
import magic.generator.DefaultDeckGenerator;
import java.util.Properties;
@ -112,8 +113,25 @@ public class MagicPlayerDefinition {
deck.setContent(aDeck);
}
void generateDeck(final DefaultDeckGenerator generator) {
generator.generateDeck(DECK_SIZE, profile, deck);
public DefaultDeckGenerator getDeckGenerator() {
String name = getProfile().getDeckGeneratorName();
if (name == null) {
return null;
}
return DeckGenerators.getInstance().getDeckGenerator(name);
}
void generateDeck(final DefaultDeckGenerator defaultGenerator) {
DefaultDeckGenerator customGenerator = getDeckGenerator();
if(customGenerator == null) {
defaultGenerator.generateDeck(DECK_SIZE, profile, deck);
} else {
customGenerator.generateDeck(DECK_SIZE, profile, deck);
}
addBasicLandsToDeck();
}

View File

@ -213,12 +213,8 @@ public class MagicTournament {
final MagicCubeDefinition cubeDefinition=CubeDefinitions.getInstance().getCubeDefinition(configuration.getCube());
final DefaultDeckGenerator generator = new DefaultDeckGenerator(cubeDefinition);
for (final MagicPlayerDefinition player : playerDefinitions) {
if (player.getProfile().getNrOfColors() == 0) {
if(player.getProfile().getDeckGeneratorName() != null) {
player.generateDeck(new magic.generator.KnightDeckGenerator());
} else {
DeckUtils.loadRandomDeck(player);
}
if(player.getDeckGenerator() == null && player.getProfile().getNrOfColors() == 0) {
DeckUtils.loadRandomDeck(player);
} else {
player.generateDeck(generator);
}

View File

@ -2,6 +2,7 @@ package magic.ui;
import magic.ai.MagicAIImpl;
import magic.data.CubeDefinitions;
import magic.data.DeckGenerators;
import magic.data.IconImages;
import magic.data.TournamentConfig;
import magic.model.MagicColor;
@ -35,6 +36,8 @@ public class TournamentDialog extends JDialog implements ActionListener {
private static final long serialVersionUID = 1L;
private static final String SEPARATOR = "----";
private final MagicFrame frame;
private final AvatarPanel avatarPanel;
private final JTextField nameTextField;
@ -264,8 +267,14 @@ public class TournamentDialog extends JDialog implements ActionListener {
model.addElement("w");
model.addElement("*");
model.addElement("@");
model.addElement("---");
model.addElement("Knight");
if(DeckGenerators.getInstance().getNrGenerators() > 0) {
model.addElement(SEPARATOR);
for(String generatorName : DeckGenerators.getInstance().getGeneratorNames()) {
model.addElement(generatorName);
}
}
setModel(model);
setSelectedItem(colors);
this.setFocusable(false);
@ -278,27 +287,27 @@ public class TournamentDialog extends JDialog implements ActionListener {
final int index,
final boolean isSelected,
final boolean cellHasFocus) {
final String colors=(String)value;
final String selectedVal = (String) value;
if(colors == "---") {
if(selectedVal == SEPARATOR) {
return new javax.swing.JSeparator(javax.swing.JSeparator.HORIZONTAL);
} else if(colors == "Knight") {
} else if(DeckGenerators.getInstance().getGeneratorNames().contains(selectedVal)) {
final JPanel panel=new JPanel(new GridLayout(1,1));
panel.setBorder(FontsAndBorders.EMPTY_BORDER);
if (isSelected) {
panel.setBackground(Color.LIGHT_GRAY);
}
JLabel label = new JLabel(colors, JLabel.CENTER);
JLabel label = new JLabel(selectedVal, JLabel.CENTER);
label.setFont(FontsAndBorders.FONT2);
panel.add(label);
return panel;
} else {
final JPanel panel=new JPanel(new GridLayout(1,3));
for (int i=0;i<colors.length();i++) {
for (int i=0;i<selectedVal.length();i++) {
final char ch=colors.charAt(i);
final char ch = selectedVal.charAt(i);
final ImageIcon icon;
switch (ch) {
case '*': icon=IconImages.ANY; break;