mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
deck import in drafted deck editor
This commit is contained in:
@@ -13,14 +13,10 @@ import forge.util.storage.IStorage;
|
|||||||
import forge.util.storage.StorageBase;
|
import forge.util.storage.StorageBase;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class holding game invariants, such as cards, editions, game formats. All that data, which is not supposed to be changed by player
|
* The class holding game invariants, such as cards, editions, game formats. All that data, which is not supposed to be changed by player
|
||||||
*
|
*
|
||||||
* @author Max
|
* @author Max
|
||||||
@@ -165,4 +161,28 @@ public class StaticData {
|
|||||||
public CardDb getVariantCards() {
|
public CardDb getVariantCards() {
|
||||||
return variantCards;
|
return variantCards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PaperCard getCardByEditionDate(PaperCard card, Date editionDate) {
|
||||||
|
|
||||||
|
PaperCard c = this.getCommonCards().getCardFromEdition(card.getName(), editionDate, CardDb.SetPreference.LatestCoreExp, card.getArtIndex());
|
||||||
|
|
||||||
|
if (null != c) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = this.getCommonCards().getCardFromEdition(card.getName(), editionDate, CardDb.SetPreference.LatestCoreExp, -1);
|
||||||
|
|
||||||
|
if (null != c) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = this.getCommonCards().getCardFromEdition(card.getName(), editionDate, CardDb.SetPreference.Latest, -1);
|
||||||
|
|
||||||
|
if (null != c) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
// I give up!
|
||||||
|
return card;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -469,6 +469,15 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
|
|||||||
}
|
}
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getEarliestDateWithAllCards(CardPool cardPool) {
|
||||||
|
CardEdition earliestSet = StaticData.instance().getEditions().getEarliestEditionWithAllCards(cardPool);
|
||||||
|
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(earliestSet.getDate());
|
||||||
|
cal.add(Calendar.DATE, 1);
|
||||||
|
return cal.getTime();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Predicates {
|
public static class Predicates {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import com.google.common.collect.Lists;
|
|||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
import forge.card.CardDb.SetPreference;
|
import forge.card.CardDb.SetPreference;
|
||||||
import forge.card.CardDb;
|
import forge.card.CardDb;
|
||||||
import forge.card.CardEdition;
|
|
||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
|
|
||||||
@@ -218,36 +217,27 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void convertByXitaxMethod() {
|
private void convertByXitaxMethod() {
|
||||||
CardEdition earliestSet = StaticData.instance().getEditions().getEarliestEditionWithAllCards(getAllCardsInASinglePool());
|
Date dateWithAllCards = StaticData.instance().getEditions().getEarliestDateWithAllCards(getAllCardsInASinglePool());
|
||||||
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
cal.setTime(earliestSet.getDate());
|
|
||||||
cal.add(Calendar.DATE, 1);
|
|
||||||
Date dayAfterNewestSetRelease = cal.getTime();
|
|
||||||
|
|
||||||
for(Entry<DeckSection, CardPool> p : parts.entrySet()) {
|
for(Entry<DeckSection, CardPool> p : parts.entrySet()) {
|
||||||
if( p.getKey() == DeckSection.Planes || p.getKey() == DeckSection.Schemes || p.getKey() == DeckSection.Avatar)
|
if( p.getKey() == DeckSection.Planes || p.getKey() == DeckSection.Schemes || p.getKey() == DeckSection.Avatar)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CardPool newPool = new CardPool();
|
CardPool newPool = new CardPool();
|
||||||
|
|
||||||
for(Entry<PaperCard, Integer> cp : p.getValue()){
|
for(Entry<PaperCard, Integer> cp : p.getValue()){
|
||||||
String cardName = cp.getKey().getName();
|
PaperCard card = cp.getKey();
|
||||||
int artIndex = cp.getKey().getArtIndex();
|
int count = cp.getValue();
|
||||||
|
|
||||||
PaperCard c = StaticData.instance().getCommonCards().getCardFromEdition(cardName, dayAfterNewestSetRelease, SetPreference.LatestCoreExp, artIndex);
|
PaperCard replacementCard = StaticData.instance().getCardByEditionDate(card, dateWithAllCards);
|
||||||
if( null == c ) {
|
|
||||||
c = StaticData.instance().getCommonCards().getCardFromEdition(cardName, dayAfterNewestSetRelease, SetPreference.LatestCoreExp, -1);
|
if (replacementCard.getArtIndex() == card.getArtIndex()) {
|
||||||
if( c == null)
|
newPool.add(card, count);
|
||||||
c = StaticData.instance().getCommonCards().getCardFromEdition(cardName, dayAfterNewestSetRelease, SetPreference.Latest, -1);
|
} else {
|
||||||
|
newPool.add(card.getName(), card.getEdition(), count); // this is to randomize art
|
||||||
if( c != null ) {
|
}
|
||||||
newPool.add(cardName, c.getEdition(), cp.getValue()); // this is to randomize art of all those cards
|
|
||||||
} else // I give up!
|
|
||||||
newPool.add(cp.getKey(), cp.getValue());
|
|
||||||
} else
|
|
||||||
newPool.add(c, cp.getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parts.put(p.getKey(), newPool);
|
parts.put(p.getKey(), newPool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -302,6 +292,14 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void importDeck(Deck deck) {
|
||||||
|
DeckSection[] sections = new DeckSection[] {DeckSection.Main, DeckSection.Sideboard};
|
||||||
|
for (DeckSection section: sections) {
|
||||||
|
this.putSection(section, deck.getOrCreate(section));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getImageKey(boolean altState) {
|
public String getImageKey(boolean altState) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public abstract class DeckBase implements Serializable, Comparable<DeckBase>, In
|
|||||||
/**
|
/**
|
||||||
* Sets the comment.
|
* Sets the comment.
|
||||||
*
|
*
|
||||||
* @param comment the new comment
|
* @param comment0 the new comment
|
||||||
*/
|
*/
|
||||||
public void setComment(final String comment0) {
|
public void setComment(final String comment0) {
|
||||||
comment = comment0;
|
comment = comment0;
|
||||||
@@ -148,4 +148,6 @@ public abstract class DeckBase implements Serializable, Comparable<DeckBase>, In
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean isEmpty();
|
public abstract boolean isEmpty();
|
||||||
|
|
||||||
|
public abstract void importDeck(Deck deck);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,10 @@
|
|||||||
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.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Write javadoc for this type.
|
* TODO: Write javadoc for this type.
|
||||||
@@ -143,7 +142,7 @@ public class DeckGroup extends DeckBase {
|
|||||||
return arg1.getName();
|
return arg1.getName();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public static final Function<DeckGroup, Deck> FN_HUMAN_DECK = new Function<DeckGroup, Deck>() {
|
public static final Function<DeckGroup, Deck> FN_HUMAN_DECK = new Function<DeckGroup, Deck>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -161,4 +160,100 @@ 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ 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;
|
||||||
@@ -144,10 +145,15 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(final ActionEvent e) {
|
public void actionPerformed(final ActionEvent e) {
|
||||||
final Deck toSet = controller.accept();
|
final Deck deck = controller.accept();
|
||||||
if (toSet == null) { return; }
|
if (deck == null) { return; }
|
||||||
|
|
||||||
|
DeckController<TModel> controller = DeckImport.this.host.getDeckController();
|
||||||
|
TModel model = controller.getModel();
|
||||||
|
|
||||||
|
model.importDeck(deck);
|
||||||
|
controller.setModel(model);
|
||||||
|
|
||||||
DeckImport.this.host.getDeckController().setModel((TModel) toSet);
|
|
||||||
DeckImport.this.processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
|
DeckImport.this.processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -188,6 +188,11 @@ 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user