forked from External/mage
deck format change
This commit is contained in:
parent
3cb1c2bf15
commit
ba8532ea86
18 changed files with 127 additions and 51 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -86,7 +86,7 @@ public class DeckGenerator {
|
|||
File tmp = File.createTempFile("tempDeck" + UUID.randomUUID().toString(), ".dck");
|
||||
tmp.createNewFile();
|
||||
deck.setName("Generated-Deck-" + UUID.randomUUID());
|
||||
deck.getDeckCardLists().save(tmp.getAbsolutePath());
|
||||
Sets.saveDeck(tmp.getAbsolutePath(), deck.getDeckCardLists());
|
||||
//JOptionPane.showMessageDialog(null, "Deck has been generated.");
|
||||
return tmp.getAbsolutePath();
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ import java.lang.reflect.Constructor;
|
|||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.sets.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -300,7 +301,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
File file = fcSelectDeck.getSelectedFile();
|
||||
try {
|
||||
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||
deck = Deck.load(DeckCardLists.load(file.getPath()), true);
|
||||
deck = Deck.load(Sets.loadDeck(file.getPath()), true);
|
||||
} catch (GameException ex) {
|
||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), ex.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE);
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -330,7 +331,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
if (!fileName.endsWith(".dck"))
|
||||
fileName += ".dck";
|
||||
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||
deck.getDeckCardLists().save(fileName);
|
||||
Sets.saveDeck(fileName, deck.getDeckCardLists());
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(DeckEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import javax.swing.JOptionPane;
|
|||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.client.remote.Session;
|
||||
import mage.client.util.PhaseManager;
|
||||
import mage.sets.Sets;
|
||||
import mage.util.Logging;
|
||||
|
||||
/**
|
||||
|
|
@ -138,7 +139,7 @@ public class JoinTableDialog extends MageDialog {
|
|||
Session session = MageFrame.getSession();
|
||||
try {
|
||||
PhaseManager.getInstance().setName(this.newPlayerPanel.getPlayerName());
|
||||
joined = session.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), DeckCardLists.load(this.newPlayerPanel.getDeckFile()));
|
||||
joined = session.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), Sets.loadDeck(this.newPlayerPanel.getDeckFile()));
|
||||
} catch (Exception ex) {
|
||||
handleError(ex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ import mage.client.remote.Session;
|
|||
import mage.client.table.TablePlayerPanel;
|
||||
import mage.client.util.Event;
|
||||
import mage.client.util.Listener;
|
||||
import mage.sets.Sets;
|
||||
import mage.util.Logging;
|
||||
import mage.view.GameTypeView;
|
||||
import mage.view.TableView;
|
||||
|
|
@ -289,7 +290,7 @@ public class NewTableDialog extends MageDialog {
|
|||
(MultiplayerAttackOption)this.cbAttackOption.getSelectedItem(),
|
||||
(RangeOfInfluence)this.cbRange.getSelectedItem());
|
||||
try {
|
||||
if (session.joinTable(roomId, table.getTableId(), this.player1Panel.getPlayerName(), DeckCardLists.load(this.player1Panel.getDeckFile()))) {
|
||||
if (session.joinTable(roomId, table.getTableId(), this.player1Panel.getPlayerName(), Sets.loadDeck(this.player1Panel.getDeckFile()))) {
|
||||
for (TablePlayerPanel player: players) {
|
||||
if (!player.getPlayerType().equals("Human")) {
|
||||
if (!player.joinTable(roomId, table.getTableId())) {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import java.util.logging.Logger;
|
|||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.sets.Sets;
|
||||
import mage.view.PlayerView;
|
||||
|
||||
/**
|
||||
|
|
@ -156,13 +157,11 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
|
||||
private void btnCheatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCheatActionPerformed
|
||||
try {
|
||||
MageFrame.getSession().cheat(gameId, playerId, DeckCardLists.load("cheat.dck"));
|
||||
MageFrame.getSession().cheat(gameId, playerId, Sets.loadDeck("cheat.dck"));
|
||||
} catch (FileNotFoundException ex) {
|
||||
Logger.getLogger(PlayAreaPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(PlayAreaPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
Logger.getLogger(PlayAreaPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}//GEN-LAST:event_btnCheatActionPerformed
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import mage.client.remote.Session;
|
|||
import mage.client.util.Config;
|
||||
import mage.client.util.Event;
|
||||
import mage.client.util.Listener;
|
||||
import mage.sets.Sets;
|
||||
import mage.util.Logging;
|
||||
|
||||
/**
|
||||
|
|
@ -81,7 +82,7 @@ public class TablePlayerPanel extends javax.swing.JPanel {
|
|||
|
||||
public boolean joinTable(UUID roomId, UUID tableId) throws FileNotFoundException, IOException, ClassNotFoundException {
|
||||
if (!this.cbPlayerType.getSelectedItem().equals("Human")) {
|
||||
return session.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), DeckCardLists.load(this.newPlayerPanel.getDeckFile()));
|
||||
return session.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), Sets.loadDeck(this.newPlayerPanel.getDeckFile()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ import mage.client.dialog.TableWaitingDialog;
|
|||
import mage.client.remote.MageRemoteException;
|
||||
import mage.client.remote.Session;
|
||||
import mage.client.util.ButtonColumn;
|
||||
import mage.sets.Sets;
|
||||
import mage.util.Logging;
|
||||
import mage.view.TableView;
|
||||
|
||||
|
|
@ -293,13 +294,13 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
roomId,
|
||||
table.getTableId(),
|
||||
"Human",
|
||||
DeckCardLists.load("test.dck")
|
||||
Sets.loadDeck("test.dck")
|
||||
);
|
||||
session.joinTable(
|
||||
roomId,
|
||||
table.getTableId(),
|
||||
"Computer",
|
||||
DeckCardLists.load("test.dck")
|
||||
Sets.loadDeck("test.dck")
|
||||
);
|
||||
hideTables();
|
||||
session.startGame(roomId, table.getTableId());
|
||||
|
|
|
|||
|
|
@ -28,11 +28,20 @@
|
|||
|
||||
package mage.sets;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -89,4 +98,91 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DeckCardLists loadDeck(String file) throws FileNotFoundException {
|
||||
DeckCardLists deckList = new DeckCardLists();
|
||||
|
||||
File f = new File(file);
|
||||
Scanner scanner = new Scanner(f);
|
||||
Pattern pattern = Pattern.compile("(SB:)?\\s*(\\d*)\\s*\\[([a-zA-Z0-9]{3}):(\\d*)\\].*");
|
||||
try {
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine().trim();
|
||||
if (line.startsWith("#")) continue;
|
||||
Matcher m = pattern.matcher(line);
|
||||
if (m.matches()) {
|
||||
boolean sideboard = false;
|
||||
if (m.group(1) != null && m.group(1).equals("SB:"))
|
||||
sideboard = true;
|
||||
int count = Integer.parseInt(m.group(2));
|
||||
String setCode = m.group(3);
|
||||
int cardNum = Integer.parseInt(m.group(4));
|
||||
ExpansionSet set = Sets.findSet(setCode);
|
||||
String card = set.findCard(cardNum);
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!sideboard) {
|
||||
deckList.getCards().add(card);
|
||||
}
|
||||
else {
|
||||
deckList.getSideboard().add(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (line.startsWith("NAME:")) {
|
||||
deckList.setName(line.substring(5, line.length()));
|
||||
}
|
||||
else if (line.startsWith("AUTHOR:")) {
|
||||
deckList.setAuthor(line.substring(7, line.length()));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
return deckList;
|
||||
}
|
||||
|
||||
public static void saveDeck(String file, DeckCardLists deck) throws FileNotFoundException {
|
||||
PrintWriter out = new PrintWriter(file);
|
||||
Map<String, Integer> cards = new HashMap<String, Integer>();
|
||||
Map<String, Integer> sideboard = new HashMap<String, Integer>();
|
||||
try {
|
||||
if (deck.getName() != null && deck.getName().length() > 0)
|
||||
out.println("NAME:" + deck.getName());
|
||||
if (deck.getAuthor() != null && deck.getAuthor().length() > 0)
|
||||
out.println("AUTHOR:" + deck.getAuthor());
|
||||
for (String cardClass: deck.getCards()) {
|
||||
if (cards.containsKey(cardClass)) {
|
||||
cards.put(cardClass, cards.get(cardClass) + 1);
|
||||
}
|
||||
else {
|
||||
cards.put(cardClass, 1);
|
||||
}
|
||||
}
|
||||
for (String cardClass: deck.getSideboard()) {
|
||||
if (sideboard.containsKey(cardClass)) {
|
||||
sideboard.put(cardClass, sideboard.get(cardClass) + 1);
|
||||
}
|
||||
else {
|
||||
sideboard.put(cardClass, 1);
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry: cards.entrySet()) {
|
||||
Card card = CardImpl.createCard(entry.getKey());
|
||||
if (card != null) {
|
||||
out.printf("%d [%s:%d] %s%n", entry.getValue(), card.getExpansionSetCode(), card.getCardNumber(), card.getName());
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry: sideboard.entrySet()) {
|
||||
Card card = CardImpl.createCard(entry.getKey());
|
||||
if (card != null) {
|
||||
out.printf("SB: %d [%s:%d] %s%n", entry.getValue(), card.getExpansionSetCode(), card.getCardNumber(), card.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,6 +143,14 @@ public abstract class ExpansionSet implements Serializable {
|
|||
return null;
|
||||
}
|
||||
|
||||
public String findCard(int cardNum) {
|
||||
for (Card card: createCards()) {
|
||||
if (card.getCardNumber() == cardNum)
|
||||
return card.getClass().getCanonicalName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected ArrayList<Class> getCardClassesForPackage(String packageName) {
|
||||
ArrayList<Class> classes = new ArrayList<Class>();
|
||||
// Get a File object for the package
|
||||
|
|
|
|||
|
|
@ -28,19 +28,9 @@
|
|||
|
||||
package mage.cards.decks;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -49,39 +39,10 @@ import java.util.logging.Logger;
|
|||
public class DeckCardLists implements Serializable {
|
||||
|
||||
private String name;
|
||||
private String author;
|
||||
private List<String> cards = new ArrayList<String>();
|
||||
private List<String> sideboard = new ArrayList<String>();
|
||||
|
||||
public static DeckCardLists load(String file) throws FileNotFoundException, IOException, ClassNotFoundException {
|
||||
|
||||
DeckCardLists deckList = new DeckCardLists();
|
||||
|
||||
FileInputStream fis;
|
||||
ObjectInputStream ois;
|
||||
|
||||
fis = new FileInputStream(file);
|
||||
ois = new ObjectInputStream(fis);
|
||||
try {
|
||||
deckList = (DeckCardLists) ois.readObject();
|
||||
return deckList;
|
||||
} finally {
|
||||
ois.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void save(String file) throws FileNotFoundException, IOException {
|
||||
|
||||
FileOutputStream fs = new FileOutputStream(file);
|
||||
ObjectOutputStream os = new ObjectOutputStream(fs);
|
||||
try {
|
||||
os.writeObject(this);
|
||||
} finally {
|
||||
os.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cards
|
||||
*/
|
||||
|
|
@ -118,4 +79,11 @@ public class DeckCardLists implements Serializable {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue