mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Support Import, Open, New deck, Save As
in all deck editors with finite catalog
This commit is contained in:
@@ -24,6 +24,7 @@ import forge.StaticData;
|
|||||||
import forge.card.CardDb;
|
import forge.card.CardDb;
|
||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
|
import forge.util.ItemPool;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -291,17 +292,13 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void importDeck(Deck deck) {
|
|
||||||
deck.loadDeferredSections();
|
|
||||||
|
|
||||||
for (DeckSection section: deck.parts.keySet()) {
|
|
||||||
this.putSection(section, deck.get(section));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getImageKey(boolean altState) {
|
public String getImageKey(boolean altState) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Deck getHumanDeck() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,10 +18,8 @@
|
|||||||
package forge.deck;
|
package forge.deck;
|
||||||
|
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
public abstract class DeckBase implements Serializable, Comparable<DeckBase>, InventoryItem {
|
public abstract class DeckBase implements Serializable, Comparable<DeckBase>, InventoryItem {
|
||||||
private static final long serialVersionUID = -7538150536939660052L;
|
private static final long serialVersionUID = -7538150536939660052L;
|
||||||
// gameType is from Constant.GameType, like GameType.Regular
|
// gameType is from Constant.GameType, like GameType.Regular
|
||||||
@@ -74,6 +72,7 @@ public abstract class DeckBase implements Serializable, Comparable<DeckBase>, In
|
|||||||
public String getDirectory() {
|
public String getDirectory() {
|
||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDirectory(String directory0) {
|
public void setDirectory(String directory0) {
|
||||||
directory = directory0;
|
directory = directory0;
|
||||||
}
|
}
|
||||||
@@ -149,5 +148,5 @@ public abstract class DeckBase implements Serializable, Comparable<DeckBase>, In
|
|||||||
|
|
||||||
public abstract boolean isEmpty();
|
public abstract boolean isEmpty();
|
||||||
|
|
||||||
public abstract void importDeck(Deck deck);
|
public abstract Deck getHumanDeck();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,6 @@
|
|||||||
package forge.deck;
|
package forge.deck;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import forge.StaticData;
|
|
||||||
import forge.item.PaperCard;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,7 +44,8 @@ public class DeckGroup extends DeckBase {
|
|||||||
*
|
*
|
||||||
* @return the human deck
|
* @return the human deck
|
||||||
*/
|
*/
|
||||||
public final Deck getHumanDeck() {
|
@Override
|
||||||
|
public Deck getHumanDeck() {
|
||||||
return humanDeck;
|
return humanDeck;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,100 +158,4 @@ public class DeckGroup extends DeckBase {
|
|||||||
public String getImageKey(boolean altState) {
|
public String getImageKey(boolean altState) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void importDeck(Deck deck) {
|
|
||||||
CardPool draftedCards = this.getHumanDeck().getAllCardsInASinglePool(false);
|
|
||||||
|
|
||||||
this.getHumanDeck().putSection(DeckSection.Main, new CardPool());
|
|
||||||
this.getHumanDeck().putSection(DeckSection.Sideboard, new CardPool());
|
|
||||||
|
|
||||||
HashMap<String, Integer> countByName = getCountByName(deck);
|
|
||||||
|
|
||||||
addFromDraftedCardPool(countByName, draftedCards);
|
|
||||||
addBasicLands(deck, countByName, draftedCards);
|
|
||||||
}
|
|
||||||
|
|
||||||
private HashMap<String, Integer> getCountByName(Deck deck) {
|
|
||||||
HashMap<String, Integer> result = new HashMap<String, Integer>();
|
|
||||||
|
|
||||||
for (Map.Entry<PaperCard, Integer> entry: deck.getMain()) {
|
|
||||||
PaperCard importedCard = entry.getKey();
|
|
||||||
|
|
||||||
Integer previousCount = result.getOrDefault(importedCard.getName(), 0);
|
|
||||||
int countToAdd = entry.getValue();
|
|
||||||
|
|
||||||
result.put(importedCard.getName(), countToAdd + previousCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addFromDraftedCardPool(HashMap<String, Integer> countByName, CardPool availableCards) {
|
|
||||||
for (Map.Entry<PaperCard, Integer> entry: availableCards) {
|
|
||||||
|
|
||||||
PaperCard availableCard = entry.getKey();
|
|
||||||
Integer availableCount = entry.getValue();
|
|
||||||
int countToAdd = countByName.getOrDefault(availableCard.getName(), 0);
|
|
||||||
|
|
||||||
if (availableCard.getRules().getType().isBasicLand()) {
|
|
||||||
// basic lands are added regardless from drafted cards
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int countMain = Math.min(availableCount, countToAdd);
|
|
||||||
|
|
||||||
if (countMain > 0) {
|
|
||||||
this.getHumanDeck().getMain().add(availableCard, countMain);
|
|
||||||
countByName.put(availableCard.getName(), countToAdd - countMain);
|
|
||||||
}
|
|
||||||
|
|
||||||
int countSideboard = availableCount - countMain;
|
|
||||||
|
|
||||||
if (countSideboard > 0) {
|
|
||||||
CardPool sideboard = this.getHumanDeck().getOrCreate(DeckSection.Sideboard);
|
|
||||||
sideboard.add(availableCard, countSideboard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addBasicLands(Deck deck, HashMap<String, Integer> countByName, CardPool availableCards) {
|
|
||||||
HashMap<String, PaperCard> basicLandsByName = getBasicLandsByName(deck, countByName);
|
|
||||||
|
|
||||||
Date dateWithAllCards = StaticData.instance().getEditions().getEarliestDateWithAllCards(availableCards);
|
|
||||||
for (String cardName: countByName.keySet()) {
|
|
||||||
|
|
||||||
PaperCard card = basicLandsByName.getOrDefault(cardName, null);
|
|
||||||
|
|
||||||
if (card == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int countToAdd = countByName.get(cardName);
|
|
||||||
|
|
||||||
card = StaticData.instance().getCardByEditionDate(card, dateWithAllCards);
|
|
||||||
this.getHumanDeck().getMain().add(card.getName(), card.getEdition(), countToAdd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private HashMap<String, PaperCard> getBasicLandsByName(Deck deck, HashMap<String, Integer> countByName) {
|
|
||||||
HashMap<String, PaperCard> result = new HashMap<String, PaperCard>();
|
|
||||||
|
|
||||||
for (Map.Entry<PaperCard, Integer> entry: deck.getMain()) {
|
|
||||||
PaperCard card = entry.getKey();
|
|
||||||
|
|
||||||
if (!card.getRules().getType().isBasicLand()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.containsKey(card.getName())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.put(card.getName(), card);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ public enum DeckSection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String valToCompate = value.trim();
|
final String valToCompare = value.trim();
|
||||||
for (final DeckSection v : DeckSection.values()) {
|
for (final DeckSection v : DeckSection.values()) {
|
||||||
if (v.name().compareToIgnoreCase(valToCompate) == 0) {
|
if (v.name().compareToIgnoreCase(valToCompare) == 0) {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ public enum CDeckEditorUI implements ICDoc {
|
|||||||
final DeckProxy deck = vAllDecks.getLstDecks().stringToItem(currentDeckStr);
|
final DeckProxy deck = vAllDecks.getLstDecks().stringToItem(currentDeckStr);
|
||||||
if (deck != null) {
|
if (deck != null) {
|
||||||
vAllDecks.getLstDecks().setSelectedItem(deck);
|
vAllDecks.getLstDecks().setSelectedItem(deck);
|
||||||
childController.getDeckController().load(deck.getPath(), deck.getName());
|
getCurrentEditorController().getDeckController().load(deck.getPath(), deck.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,20 +20,16 @@ package forge.screens.deckeditor;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
|
|
||||||
import forge.deck.Deck;
|
import forge.deck.*;
|
||||||
import forge.deck.DeckBase;
|
|
||||||
import forge.deck.DeckImportController;
|
|
||||||
import forge.deck.DeckRecognizer;
|
|
||||||
import forge.deck.DeckRecognizer.TokenType;
|
import forge.deck.DeckRecognizer.TokenType;
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
import forge.screens.deckeditor.controllers.ACEditorBase;
|
import forge.screens.deckeditor.controllers.ACEditorBase;
|
||||||
import forge.screens.deckeditor.controllers.DeckController;
|
|
||||||
import forge.toolbox.FButton;
|
import forge.toolbox.FButton;
|
||||||
import forge.toolbox.FCheckBox;
|
import forge.toolbox.FCheckBox;
|
||||||
import forge.toolbox.FComboBox;
|
import forge.toolbox.FComboBox;
|
||||||
@@ -148,12 +144,7 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
|||||||
final Deck deck = controller.accept();
|
final Deck deck = controller.accept();
|
||||||
if (deck == null) { return; }
|
if (deck == null) { return; }
|
||||||
|
|
||||||
DeckController<TModel> controller = DeckImport.this.host.getDeckController();
|
DeckImport.this.host.getDeckController().loadDeck(deck);
|
||||||
TModel model = controller.getModel();
|
|
||||||
|
|
||||||
model.importDeck(deck);
|
|
||||||
controller.setModel(model);
|
|
||||||
|
|
||||||
DeckImport.this.processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
|
DeckImport.this.processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -173,6 +164,7 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
|||||||
parseAndDisplay();
|
parseAndDisplay();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.newEditionCheck.addActionListener(reparse);
|
this.newEditionCheck.addActionListener(reparse);
|
||||||
this.onlyCoreExpCheck.addActionListener(reparse);
|
this.onlyCoreExpCheck.addActionListener(reparse);
|
||||||
this.yearDropdown.addActionListener(reparse);
|
this.yearDropdown.addActionListener(reparse);
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.InputEvent;
|
import java.awt.event.InputEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@@ -186,14 +185,7 @@ public abstract class ACEditorBase<TItem extends InventoryItem, TModel extends D
|
|||||||
final CardLimit limit = getCardLimit();
|
final CardLimit limit = getCardLimit();
|
||||||
final DeckController<TModel> controller = getDeckController();
|
final DeckController<TModel> controller = getDeckController();
|
||||||
|
|
||||||
Deck deck = null;
|
Deck deck = getHumanDeck();
|
||||||
if (controller != null) {
|
|
||||||
if (controller.getModel() instanceof Deck) {
|
|
||||||
deck = (Deck)controller.getModel(); // constructed deck
|
|
||||||
} else if (controller.getModel() instanceof DeckGroup) {
|
|
||||||
deck = ((DeckGroup)controller.getModel()).getHumanDeck(); // limited deck
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterable<Entry<String,Integer>> cardsByName = null;
|
Iterable<Entry<String,Integer>> cardsByName = null;
|
||||||
if (deck != null) {
|
if (deck != null) {
|
||||||
@@ -248,6 +240,7 @@ public abstract class ACEditorBase<TItem extends InventoryItem, TModel extends D
|
|||||||
protected abstract void onRemoveItems(Iterable<Entry<TItem, Integer>> items, boolean toAlternate);
|
protected abstract void onRemoveItems(Iterable<Entry<TItem, Integer>> items, boolean toAlternate);
|
||||||
|
|
||||||
protected abstract void buildAddContextMenu(EditorContextMenuBuilder cmb);
|
protected abstract void buildAddContextMenu(EditorContextMenuBuilder cmb);
|
||||||
|
|
||||||
protected abstract void buildRemoveContextMenu(EditorContextMenuBuilder cmb);
|
protected abstract void buildRemoveContextMenu(EditorContextMenuBuilder cmb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -262,6 +255,10 @@ public abstract class ACEditorBase<TItem extends InventoryItem, TModel extends D
|
|||||||
*/
|
*/
|
||||||
public abstract DeckController<TModel> getDeckController();
|
public abstract DeckController<TModel> getDeckController();
|
||||||
|
|
||||||
|
protected Deck getHumanDeck() {
|
||||||
|
return getDeckController().getModel().getHumanDeck();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when switching away from or closing the editor wants to exit. Should confirm save options.
|
* Called when switching away from or closing the editor wants to exit. Should confirm save options.
|
||||||
*
|
*
|
||||||
@@ -598,5 +595,4 @@ public abstract class ACEditorBase<TItem extends InventoryItem, TModel extends D
|
|||||||
InputEvent.ALT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
|
InputEvent.ALT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import forge.screens.deckeditor.views.VCurrentDeck;
|
|||||||
* Controls the "current deck" panel in the deck editor UI.
|
* Controls the "current deck" panel in the deck editor UI.
|
||||||
*
|
*
|
||||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public enum CCurrentDeck implements ICDoc {
|
public enum CCurrentDeck implements ICDoc {
|
||||||
SINGLETON_INSTANCE;
|
SINGLETON_INSTANCE;
|
||||||
@@ -142,7 +141,7 @@ public enum CCurrentDeck implements ICDoc {
|
|||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
((DeckController<DeckBase>) CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController()).newModel();
|
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController().loadDeck(new Deck());
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().requestFocusInWindow();
|
VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().requestFocusInWindow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -161,9 +160,9 @@ public enum CCurrentDeck implements ICDoc {
|
|||||||
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
try {
|
try {
|
||||||
((DeckController<DeckBase>) CDeckEditorUI.SINGLETON_INSTANCE
|
CDeckEditorUI.SINGLETON_INSTANCE
|
||||||
.getCurrentEditorController().getDeckController())
|
.getCurrentEditorController().getDeckController()
|
||||||
.setModel(DeckSerializer.fromFile(file));
|
.loadDeck(DeckSerializer.fromFile(file));
|
||||||
|
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
//BugReporter.reportException(ex);
|
//BugReporter.reportException(ex);
|
||||||
@@ -193,7 +192,7 @@ public enum CCurrentDeck implements ICDoc {
|
|||||||
/** */
|
/** */
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void exportDeck() {
|
private void exportDeck() {
|
||||||
final DeckController<Deck> controller = (DeckController<Deck>)
|
final DeckController<? extends DeckBase> controller =
|
||||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController();
|
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController();
|
||||||
|
|
||||||
final File filename = this.getExportFilename();
|
final File filename = this.getExportFilename();
|
||||||
@@ -204,11 +203,13 @@ public enum CCurrentDeck implements ICDoc {
|
|||||||
//create copy of deck to save under new name
|
//create copy of deck to save under new name
|
||||||
String name = filename.getName();
|
String name = filename.getName();
|
||||||
name = name.substring(0, name.lastIndexOf(".")); //remove extension
|
name = name.substring(0, name.lastIndexOf(".")); //remove extension
|
||||||
final Deck deck = (Deck)controller.getModel().copyTo(name);
|
Deck deck = (Deck) controller.getModel().getHumanDeck().copyTo(name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DeckSerializer.writeDeck(deck, filename);
|
DeckSerializer.writeDeck(deck, filename);
|
||||||
controller.setModel(DeckSerializer.fromFile(filename)); //reload deck from file so everything is in sync
|
final Deck deserialized = DeckSerializer.fromFile(filename);
|
||||||
|
//reload deck from file so everything is in sync
|
||||||
|
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController().loadDeck(deserialized);
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
//BugReporter.reportException(ex);
|
//BugReporter.reportException(ex);
|
||||||
throw new RuntimeException("Error exporting deck." + ex);
|
throw new RuntimeException("Error exporting deck." + ex);
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package forge.screens.deckeditor.controllers;
|
||||||
|
|
||||||
|
import forge.deck.*;
|
||||||
|
import forge.gui.framework.FScreen;
|
||||||
|
import forge.item.PaperCard;
|
||||||
|
import forge.screens.match.controllers.CDetailPicture;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public abstract class CDeckEditor<TModel extends DeckBase> extends ACEditorBase<PaperCard, TModel> {
|
||||||
|
|
||||||
|
protected CDeckEditor(FScreen screen0, CDetailPicture cDetailPicture) {
|
||||||
|
super(screen0, cDetailPicture);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* While user edits the deck, the catalog content changes.
|
||||||
|
* In order to keep deck loading logic simple we need an initial card pool state to pick cards from.
|
||||||
|
*
|
||||||
|
* The method should only be used when the catalog is non infinite.
|
||||||
|
*/
|
||||||
|
protected CardPool getInitialCatalog() {
|
||||||
|
if (getCatalogManager().isInfinite()) {
|
||||||
|
throw new UnsupportedOperationException("Currently used catalog is infinite");
|
||||||
|
}
|
||||||
|
|
||||||
|
CardPool result = new CardPool();
|
||||||
|
result.addAll(getCatalogManager().getPool());
|
||||||
|
|
||||||
|
for (DeckSection section: EnumSet.allOf(DeckSection.class)) {
|
||||||
|
if (isSectionPickableFromCatalog(section)) {
|
||||||
|
result.addAll(getHumanDeck().getOrCreate(section));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Boolean isSectionImportable(DeckSection section) {
|
||||||
|
return section == DeckSection.Main;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can user pick a card from the catalog into specific section
|
||||||
|
*
|
||||||
|
* The returned value is only used when the catalog is non infinite.
|
||||||
|
* When it is infinite, the implementation may safely return null.
|
||||||
|
*/
|
||||||
|
protected Boolean isSectionPickableFromCatalog(DeckSection section) {
|
||||||
|
return isSectionImportable(section);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -51,7 +51,7 @@ import java.util.Map.Entry;
|
|||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id: CEditorCommander.java 18430 2012-11-27 22:42:36Z Hellfish $
|
* @version $Id: CEditorCommander.java 18430 2012-11-27 22:42:36Z Hellfish $
|
||||||
*/
|
*/
|
||||||
public final class CEditorCommander extends ACEditorBase<PaperCard, Deck> {
|
public final class CEditorCommander extends CDeckEditor<Deck> {
|
||||||
private final DeckController<Deck> controller;
|
private final DeckController<Deck> controller;
|
||||||
private DragCell allDecksParent = null;
|
private DragCell allDecksParent = null;
|
||||||
private DragCell deckGenParent = null;
|
private DragCell deckGenParent = null;
|
||||||
@@ -164,6 +164,11 @@ public final class CEditorCommander extends ACEditorBase<PaperCard, Deck> {
|
|||||||
this.getDeckManager().setPool(this.controller.getModel().getOrCreate(DeckSection.Main));
|
this.getDeckManager().setPool(this.controller.getModel().getOrCreate(DeckSection.Main));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean isSectionImportable(DeckSection section) {
|
||||||
|
return allSections.contains(section);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import java.util.Map.Entry;
|
|||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id: CEditorConstructed.java 24868 2014-02-17 05:08:05Z drdev $
|
* @version $Id: CEditorConstructed.java 24868 2014-02-17 05:08:05Z drdev $
|
||||||
*/
|
*/
|
||||||
public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
|
public final class CEditorConstructed extends CDeckEditor<Deck> {
|
||||||
private final DeckController<Deck> controller;
|
private final DeckController<Deck> controller;
|
||||||
private final List<DeckSection> allSections = new ArrayList<DeckSection>();
|
private final List<DeckSection> allSections = new ArrayList<DeckSection>();
|
||||||
private final ItemPool<PaperCard> normalPool, avatarPool, planePool, schemePool, conspiracyPool;
|
private final ItemPool<PaperCard> normalPool, avatarPool, planePool, schemePool, conspiracyPool;
|
||||||
@@ -278,6 +278,11 @@ public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
|
|||||||
this.getDeckManager().setPool(this.controller.getModel().getMain());
|
this.getDeckManager().setPool(this.controller.getModel().getMain());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean isSectionImportable(DeckSection section) {
|
||||||
|
return allSections.contains(section);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -40,11 +40,8 @@ import forge.screens.home.sanctioned.CSubmenuSealed;
|
|||||||
import forge.screens.match.controllers.CDetailPicture;
|
import forge.screens.match.controllers.CDetailPicture;
|
||||||
import forge.util.storage.IStorage;
|
import forge.util.storage.IStorage;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Child controller for limited deck editor UI.
|
* Child controller for limited deck editor UI.
|
||||||
@@ -54,7 +51,7 @@ import java.util.Set;
|
|||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id: DeckEditorCommon.java 12850 2011-12-26 14:55:09Z slapshot5 $
|
* @version $Id: DeckEditorCommon.java 12850 2011-12-26 14:55:09Z slapshot5 $
|
||||||
*/
|
*/
|
||||||
public final class CEditorLimited extends ACEditorBase<PaperCard, DeckGroup> {
|
public final class CEditorLimited extends CDeckEditor<DeckGroup> {
|
||||||
|
|
||||||
private final DeckController<DeckGroup> controller;
|
private final DeckController<DeckGroup> controller;
|
||||||
private DragCell allDecksParent = null;
|
private DragCell allDecksParent = null;
|
||||||
@@ -109,10 +106,6 @@ public final class CEditorLimited extends ACEditorBase<PaperCard, DeckGroup> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Deck getSelectedDeck() {
|
|
||||||
return controller.getModel().getHumanDeck();
|
|
||||||
}
|
|
||||||
|
|
||||||
//========== Overridden from ACEditorBase
|
//========== Overridden from ACEditorBase
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -163,9 +156,13 @@ public final class CEditorLimited extends ACEditorBase<PaperCard, DeckGroup> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void resetTables() {
|
public void resetTables() {
|
||||||
final Deck toEdit = this.getSelectedDeck();
|
this.getCatalogManager().setPool(getHumanDeck().getOrCreate(DeckSection.Sideboard));
|
||||||
this.getCatalogManager().setPool(toEdit.getOrCreate(DeckSection.Sideboard));
|
this.getDeckManager().setPool(getHumanDeck().getMain());
|
||||||
this.getDeckManager().setPool(toEdit.getMain());
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean isSectionImportable(DeckSection section) {
|
||||||
|
return section != DeckSection.Sideboard && allSections.contains(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -179,7 +176,7 @@ public final class CEditorLimited extends ACEditorBase<PaperCard, DeckGroup> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void addBasicLands(ACEditorBase<PaperCard, DeckGroup> editor) {
|
public static void addBasicLands(ACEditorBase<PaperCard, DeckGroup> editor) {
|
||||||
Deck deck = editor.getDeckController().getModel().getHumanDeck();
|
Deck deck = editor.getHumanDeck();
|
||||||
if (deck == null) { return; }
|
if (deck == null) { return; }
|
||||||
|
|
||||||
Set<CardEdition> availableEditionCodes = new HashSet<>();
|
Set<CardEdition> availableEditionCodes = new HashSet<>();
|
||||||
@@ -204,11 +201,11 @@ public final class CEditorLimited extends ACEditorBase<PaperCard, DeckGroup> {
|
|||||||
switch(sectionMode) {
|
switch(sectionMode) {
|
||||||
case Conspiracy:
|
case Conspiracy:
|
||||||
this.getCatalogManager().setup(ItemManagerConfig.DRAFT_CONSPIRACY);
|
this.getCatalogManager().setup(ItemManagerConfig.DRAFT_CONSPIRACY);
|
||||||
this.getDeckManager().setPool(this.getSelectedDeck().getOrCreate(DeckSection.Conspiracy));
|
this.getDeckManager().setPool(getHumanDeck().getOrCreate(DeckSection.Conspiracy));
|
||||||
break;
|
break;
|
||||||
case Main:
|
case Main:
|
||||||
this.getCatalogManager().setup(getScreen() == FScreen.DECK_EDITOR_DRAFT ? ItemManagerConfig.DRAFT_POOL : ItemManagerConfig.SEALED_POOL);
|
this.getCatalogManager().setup(getScreen() == FScreen.DECK_EDITOR_DRAFT ? ItemManagerConfig.DRAFT_POOL : ItemManagerConfig.SEALED_POOL);
|
||||||
this.getDeckManager().setPool(this.getSelectedDeck().getOrCreate(DeckSection.Main));
|
this.getDeckManager().setPool(getHumanDeck().getOrCreate(DeckSection.Main));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -228,9 +225,6 @@ public final class CEditorLimited extends ACEditorBase<PaperCard, DeckGroup> {
|
|||||||
resetUI();
|
resetUI();
|
||||||
|
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnPrintProxies().setVisible(false);
|
VCurrentDeck.SINGLETON_INSTANCE.getBtnPrintProxies().setVisible(false);
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnSaveAs().setVisible(false);
|
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnNew().setVisible(false);
|
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnOpen().setVisible(false);
|
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setEnabled(false);
|
VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setEnabled(false);
|
||||||
this.getBtnCycleSection().setVisible(true);
|
this.getBtnCycleSection().setVisible(true);
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ import java.util.Map.Entry;
|
|||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id: CEditorQuest.java 24868 2014-02-17 05:08:05Z drdev $
|
* @version $Id: CEditorQuest.java 24868 2014-02-17 05:08:05Z drdev $
|
||||||
*/
|
*/
|
||||||
public final class CEditorQuest extends ACEditorBase<PaperCard, Deck> {
|
public final class CEditorQuest extends CDeckEditor<Deck> {
|
||||||
private final QuestController questData;
|
private final QuestController questData;
|
||||||
private final DeckController<Deck> controller;
|
private final DeckController<Deck> controller;
|
||||||
private final List<DeckSection> allSections = new ArrayList<DeckSection>();
|
private final List<DeckSection> allSections = new ArrayList<DeckSection>();
|
||||||
@@ -244,8 +244,7 @@ public final class CEditorQuest extends ACEditorBase<PaperCard, Deck> {
|
|||||||
|
|
||||||
final Deck deck = this.controller.getModel();
|
final Deck deck = this.controller.getModel();
|
||||||
|
|
||||||
final ItemPool<PaperCard> cardpool = new ItemPool<PaperCard>(PaperCard.class);
|
final CardPool cardpool = getInitialCatalog();
|
||||||
cardpool.addAll(this.questData.getCards().getCardpool());
|
|
||||||
// remove bottom cards that are in the deck from the card pool
|
// remove bottom cards that are in the deck from the card pool
|
||||||
cardpool.removeAll(deck.getMain());
|
cardpool.removeAll(deck.getMain());
|
||||||
// remove sideboard cards from the catalog
|
// remove sideboard cards from the catalog
|
||||||
@@ -255,6 +254,16 @@ public final class CEditorQuest extends ACEditorBase<PaperCard, Deck> {
|
|||||||
this.getDeckManager().setPool(deck.getMain());
|
this.getDeckManager().setPool(deck.getMain());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CardPool getInitialCatalog() {
|
||||||
|
return new CardPool(this.questData.getCards().getCardpool());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean isSectionImportable(DeckSection section) {
|
||||||
|
return allSections.contains(section);
|
||||||
|
}
|
||||||
|
|
||||||
//=========== Overridden from ACEditorBase
|
//=========== Overridden from ACEditorBase
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -306,7 +315,6 @@ public final class CEditorQuest extends ACEditorBase<PaperCard, Deck> {
|
|||||||
resetUI();
|
resetUI();
|
||||||
|
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnSave().setVisible(true);
|
VCurrentDeck.SINGLETON_INSTANCE.getBtnSave().setVisible(true);
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnImport().setVisible(false);
|
|
||||||
|
|
||||||
this.getBtnCycleSection().setVisible(true);
|
this.getBtnCycleSection().setVisible(true);
|
||||||
this.getBtnCycleSection().setCommand(new UiCommand() {
|
this.getBtnCycleSection().setCommand(new UiCommand() {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package forge.screens.deckeditor.controllers;
|
|||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import forge.UiCommand;
|
import forge.UiCommand;
|
||||||
|
import forge.deck.CardPool;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.DeckGroup;
|
import forge.deck.DeckGroup;
|
||||||
import forge.deck.DeckSection;
|
import forge.deck.DeckSection;
|
||||||
@@ -58,7 +59,7 @@ import java.util.Map.Entry;
|
|||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id: CEditorQuest.java 24868 2014-02-17 05:08:05Z drdev $
|
* @version $Id: CEditorQuest.java 24868 2014-02-17 05:08:05Z drdev $
|
||||||
*/
|
*/
|
||||||
public final class CEditorQuestLimited extends ACEditorBase<PaperCard, DeckGroup> {
|
public final class CEditorQuestLimited extends CDeckEditor<DeckGroup> {
|
||||||
private final QuestController questData;
|
private final QuestController questData;
|
||||||
private final DeckController<DeckGroup> controller;
|
private final DeckController<DeckGroup> controller;
|
||||||
private final List<DeckSection> allSections = new ArrayList<DeckSection>();
|
private final List<DeckSection> allSections = new ArrayList<DeckSection>();
|
||||||
@@ -198,10 +199,6 @@ public final class CEditorQuestLimited extends ACEditorBase<PaperCard, DeckGroup
|
|||||||
cmb.addMoveItems("Move", "to sideboard");
|
cmb.addMoveItems("Move", "to sideboard");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Deck getSelectedDeck(final DeckGroup model) {
|
|
||||||
return model.getHumanDeck();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
@@ -209,9 +206,13 @@ public final class CEditorQuestLimited extends ACEditorBase<PaperCard, DeckGroup
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void resetTables() {
|
public void resetTables() {
|
||||||
final Deck toEdit = this.getSelectedDeck(this.controller.getModel());
|
this.getCatalogManager().setPool(getHumanDeck().getOrCreate(DeckSection.Sideboard));
|
||||||
this.getCatalogManager().setPool(toEdit.getOrCreate(DeckSection.Sideboard));
|
this.getDeckManager().setPool(getHumanDeck().getMain());
|
||||||
this.getDeckManager().setPool(toEdit.getMain());
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean isSectionImportable(DeckSection section) {
|
||||||
|
return section != DeckSection.Sideboard && allSections.contains(section);
|
||||||
}
|
}
|
||||||
|
|
||||||
//=========== Overridden from ACEditorBase
|
//=========== Overridden from ACEditorBase
|
||||||
@@ -246,12 +247,8 @@ public final class CEditorQuestLimited extends ACEditorBase<PaperCard, DeckGroup
|
|||||||
resetUI();
|
resetUI();
|
||||||
|
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnSave().setVisible(true);
|
VCurrentDeck.SINGLETON_INSTANCE.getBtnSave().setVisible(true);
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnImport().setVisible(false);
|
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setEnabled(false);
|
VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setEnabled(false);
|
||||||
|
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnNew().setVisible(false);
|
|
||||||
VCurrentDeck.SINGLETON_INSTANCE.getBtnOpen().setVisible(false);
|
|
||||||
|
|
||||||
deckGenParent = removeTab(VDeckgen.SINGLETON_INSTANCE);
|
deckGenParent = removeTab(VDeckgen.SINGLETON_INSTANCE);
|
||||||
allDecksParent = removeTab(VAllDecks.SINGLETON_INSTANCE);
|
allDecksParent = removeTab(VAllDecks.SINGLETON_INSTANCE);
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import java.util.Map.Entry;
|
|||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id: CEditorConstructed.java 18430 2012-11-27 22:42:36Z Hellfish $
|
* @version $Id: CEditorConstructed.java 18430 2012-11-27 22:42:36Z Hellfish $
|
||||||
*/
|
*/
|
||||||
public final class CEditorVariant extends ACEditorBase<PaperCard, Deck> {
|
public final class CEditorVariant extends CDeckEditor<Deck> {
|
||||||
private final DeckController<Deck> controller;
|
private final DeckController<Deck> controller;
|
||||||
private DragCell allDecksParent = null;
|
private DragCell allDecksParent = null;
|
||||||
private DragCell deckGenParent = null;
|
private DragCell deckGenParent = null;
|
||||||
@@ -153,6 +153,11 @@ public final class CEditorVariant extends ACEditorBase<PaperCard, Deck> {
|
|||||||
this.getDeckManager().setPool(this.controller.getModel().getOrCreate(this.sectionMode));
|
this.getDeckManager().setPool(this.controller.getModel().getOrCreate(this.sectionMode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean isSectionImportable(DeckSection section) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -17,12 +17,14 @@
|
|||||||
*/
|
*/
|
||||||
package forge.screens.deckeditor.controllers;
|
package forge.screens.deckeditor.controllers;
|
||||||
|
|
||||||
|
import forge.StaticData;
|
||||||
|
import forge.deck.*;
|
||||||
|
import forge.item.PaperCard;
|
||||||
|
import forge.util.ItemPool;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
|
||||||
import forge.deck.DeckBase;
|
|
||||||
import forge.deck.DeckProxy;
|
|
||||||
import forge.screens.deckeditor.menus.DeckFileMenu;
|
import forge.screens.deckeditor.menus.DeckFileMenu;
|
||||||
import forge.screens.deckeditor.views.VCurrentDeck;
|
import forge.screens.deckeditor.views.VCurrentDeck;
|
||||||
import forge.screens.home.gauntlet.VSubmenuGauntletBuild;
|
import forge.screens.home.gauntlet.VSubmenuGauntletBuild;
|
||||||
@@ -31,6 +33,11 @@ import forge.screens.home.gauntlet.VSubmenuGauntletQuick;
|
|||||||
import forge.screens.home.sanctioned.VSubmenuConstructed;
|
import forge.screens.home.sanctioned.VSubmenuConstructed;
|
||||||
import forge.util.storage.IStorage;
|
import forge.util.storage.IStorage;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class DeckController<T extends DeckBase> {
|
public class DeckController<T extends DeckBase> {
|
||||||
private T model;
|
private T model;
|
||||||
private boolean saved;
|
private boolean saved;
|
||||||
@@ -38,7 +45,7 @@ public class DeckController<T extends DeckBase> {
|
|||||||
private final IStorage<T> rootFolder;
|
private final IStorage<T> rootFolder;
|
||||||
private IStorage<T> currentFolder;
|
private IStorage<T> currentFolder;
|
||||||
private String modelPath;
|
private String modelPath;
|
||||||
private final ACEditorBase<?, T> view;
|
private final CDeckEditor<T> view;
|
||||||
private final Supplier<T> newModelCreator;
|
private final Supplier<T> newModelCreator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,7 +55,7 @@ public class DeckController<T extends DeckBase> {
|
|||||||
* @param view0 the view0
|
* @param view0 the view0
|
||||||
* @param newModelCreator0 the new model creator0
|
* @param newModelCreator0 the new model creator0
|
||||||
*/
|
*/
|
||||||
public DeckController(final IStorage<T> folder0, final ACEditorBase<?, T> view0, final Supplier<T> newModelCreator0) {
|
public DeckController(final IStorage<T> folder0, final CDeckEditor<T> view0, final Supplier<T> newModelCreator0) {
|
||||||
rootFolder = folder0;
|
rootFolder = folder0;
|
||||||
currentFolder = rootFolder;
|
currentFolder = rootFolder;
|
||||||
view = view0;
|
view = view0;
|
||||||
@@ -76,6 +83,128 @@ public class DeckController<T extends DeckBase> {
|
|||||||
return model == null || model.isEmpty();
|
return model == null || model.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load deck from file or clipboard
|
||||||
|
*/
|
||||||
|
public void loadDeck(Deck deck) {
|
||||||
|
|
||||||
|
if (!view.getCatalogManager().isInfinite()) {
|
||||||
|
CardPool catalogClone = new CardPool(view.getInitialCatalog());
|
||||||
|
deck = pickFromCatalog(deck, catalogClone);
|
||||||
|
ItemPool<PaperCard> catalogPool = view.getCatalogManager().getPool();
|
||||||
|
catalogPool.clear();
|
||||||
|
catalogPool.addAll(catalogClone);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DeckSection section: EnumSet.allOf(DeckSection.class)) {
|
||||||
|
if (view.isSectionImportable(section)) {
|
||||||
|
CardPool sectionCards = view.getHumanDeck().getOrCreate(section);
|
||||||
|
sectionCards.clear();
|
||||||
|
sectionCards.addAll(deck.getOrCreate(section));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onModelChanged(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Deck pickFromCatalog(Deck deck, CardPool catalog) {
|
||||||
|
Date dateWithAllCards = StaticData.instance().getEditions().getEarliestDateWithAllCards(catalog);
|
||||||
|
Deck result = new Deck();
|
||||||
|
for (DeckSection section: EnumSet.allOf(DeckSection.class)) {
|
||||||
|
if (view.isSectionImportable(section)) {
|
||||||
|
CardPool cards = pickSectionFromCatalog(catalog, deck.getOrCreate(section), dateWithAllCards);
|
||||||
|
result.putSection(section, cards);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CardPool pickSectionFromCatalog(CardPool catalog, CardPool sourceSection, Date dateWithAllCards) {
|
||||||
|
HashMap<String, Integer> countByName = groupByName(sourceSection);
|
||||||
|
HashMap<String, PaperCard> basicLandsByName = getBasicLandsByName(sourceSection);
|
||||||
|
|
||||||
|
CardPool targetSection = new CardPool();
|
||||||
|
pickFromCatalog(countByName, catalog, targetSection);
|
||||||
|
importBasicLands(countByName, basicLandsByName, dateWithAllCards, targetSection);
|
||||||
|
|
||||||
|
return targetSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashMap<String, Integer> groupByName(CardPool section) {
|
||||||
|
HashMap<String, Integer> result = new HashMap<String, Integer>();
|
||||||
|
|
||||||
|
for (Map.Entry<PaperCard, Integer> entry : section) {
|
||||||
|
PaperCard importedCard = entry.getKey();
|
||||||
|
|
||||||
|
Integer previousCount = result.getOrDefault(importedCard.getName(), 0);
|
||||||
|
int countToAdd = entry.getValue();
|
||||||
|
|
||||||
|
result.put(importedCard.getName(), countToAdd + previousCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pickFromCatalog(HashMap<String, Integer> countByName, CardPool catalog, CardPool targetSection) {
|
||||||
|
|
||||||
|
CardPool catalogClone = new CardPool(catalog); // clone to iterate modified collection
|
||||||
|
for (Map.Entry<PaperCard, Integer> entry : catalogClone) {
|
||||||
|
|
||||||
|
PaperCard availableCard = entry.getKey();
|
||||||
|
if (availableCard.getRules().getType().isBasicLand()) {
|
||||||
|
// basic lands are added regardless of catalog cards
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer availableCount = entry.getValue();
|
||||||
|
int toAddByName = countByName.getOrDefault(availableCard.getName(), 0);
|
||||||
|
int toAdd = Math.min(availableCount, toAddByName);
|
||||||
|
|
||||||
|
if (toAdd > 0) {
|
||||||
|
targetSection.add(availableCard, toAdd);
|
||||||
|
countByName.put(availableCard.getName(), toAddByName - toAdd);
|
||||||
|
catalog.remove(availableCard, toAdd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void importBasicLands(HashMap<String, Integer> countByName, HashMap<String, PaperCard> basicLandsByName, Date dateWithAllCards, CardPool targetSection) {
|
||||||
|
for (String cardName : countByName.keySet()) {
|
||||||
|
|
||||||
|
PaperCard card = basicLandsByName.getOrDefault(cardName, null);
|
||||||
|
|
||||||
|
if (card == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int countToAdd = countByName.get(cardName);
|
||||||
|
|
||||||
|
card = StaticData.instance().getCardByEditionDate(card, dateWithAllCards);
|
||||||
|
targetSection.add(card.getName(), card.getEdition(), countToAdd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashMap<String, PaperCard> getBasicLandsByName(CardPool sourceSection) {
|
||||||
|
HashMap<String, PaperCard> result = new HashMap<String, PaperCard>();
|
||||||
|
|
||||||
|
for (Map.Entry<PaperCard, Integer> entry : sourceSection) {
|
||||||
|
PaperCard card = entry.getKey();
|
||||||
|
|
||||||
|
if (!card.getRules().getType().isBasicLand()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.containsKey(card.getName())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.put(card.getName(), card);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the model.
|
* Sets the model.
|
||||||
*
|
*
|
||||||
@@ -83,9 +212,14 @@ public class DeckController<T extends DeckBase> {
|
|||||||
public void setModel(final T document) {
|
public void setModel(final T document) {
|
||||||
setModel(document, false);
|
setModel(document, false);
|
||||||
}
|
}
|
||||||
public void setModel(final T document, final boolean isStored) {
|
|
||||||
modelInStorage = isStored;
|
private void setModel(final T document, final boolean isStored) {
|
||||||
model = document;
|
model = document;
|
||||||
|
onModelChanged(isStored);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onModelChanged(boolean isStored) {
|
||||||
|
modelInStorage = isStored;
|
||||||
view.resetTables();
|
view.resetTables();
|
||||||
|
|
||||||
CStatistics.SINGLETON_INSTANCE.update();
|
CStatistics.SINGLETON_INSTANCE.update();
|
||||||
|
|||||||
@@ -1490,15 +1490,6 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
modelPath = "";
|
modelPath = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Deck getDeck() {
|
|
||||||
if (model == null) { return null; }
|
|
||||||
|
|
||||||
if (model instanceof Deck) {
|
|
||||||
return (Deck) model;
|
|
||||||
}
|
|
||||||
return ((DeckGroup) model).getHumanDeck();
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getModel() {
|
public T getModel() {
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
@@ -1537,7 +1528,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
modelPath = "";
|
modelPath = "";
|
||||||
setSaved(true);
|
setSaved(true);
|
||||||
}
|
}
|
||||||
editor.setDeck(getDeck());
|
editor.setDeck(model.getHumanDeck());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isModelInSyncWithFolder() {
|
private boolean isModelInSyncWithFolder() {
|
||||||
@@ -1661,7 +1652,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
editor.setDeck(getDeck());
|
editor.setDeck(model.getHumanDeck());
|
||||||
if (editor.saveHandler != null) {
|
if (editor.saveHandler != null) {
|
||||||
editor.saveHandler.handleEvent(new FEvent(editor, FEventType.SAVE));
|
editor.saveHandler.handleEvent(new FEvent(editor, FEventType.SAVE));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,10 @@
|
|||||||
package forge.limited;
|
package forge.limited;
|
||||||
|
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
|
import forge.deck.CardPool;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.DeckBase;
|
import forge.deck.DeckBase;
|
||||||
|
import forge.deck.DeckSection;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.item.SealedProduct;
|
import forge.item.SealedProduct;
|
||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
@@ -188,13 +190,13 @@ public class CustomLimited extends DeckBase {
|
|||||||
return cardPool.isEmpty();
|
return cardPool.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void importDeck(Deck deck) {
|
|
||||||
throw new UnsupportedOperationException("CustomDraft does not support deck import");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getImageKey(boolean altState) {
|
public String getImageKey(boolean altState) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Deck getHumanDeck() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user