From 5dcdbcfd4fca0040e0e3224ab07c1f57b87470ff Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sun, 25 Jul 2021 10:31:22 +0400 Subject: [PATCH] * GUI: fixed wrong deck validation in Deck Editor for partners and planeswalker's commanders; --- .../client/deckeditor/DeckLegalityPanel.java | 31 ++++++++++++++++++- Mage/src/main/java/mage/cards/decks/Deck.java | 1 - .../main/java/mage/cards/mock/MockCard.java | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/DeckLegalityPanel.java b/Mage.Client/src/main/java/mage/client/deckeditor/DeckLegalityPanel.java index d28f488af0..d92a684faf 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/DeckLegalityPanel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/DeckLegalityPanel.java @@ -1,9 +1,13 @@ package mage.client.deckeditor; +import mage.cards.Card; import mage.cards.decks.Deck; import mage.cards.decks.DeckValidator; +import mage.cards.mock.MockCard; +import mage.cards.mock.MockSplitCard; import mage.client.components.LegalityLabel; import mage.deck.*; +import org.apache.log4j.Logger; import javax.swing.*; import java.util.Arrays; @@ -14,6 +18,9 @@ import java.util.stream.Stream; * @author Elandril */ public class DeckLegalityPanel extends javax.swing.JPanel { + + private static final Logger logger = Logger.getLogger(DeckLegalityPanel.class); + /** * Creates new form DeckLegalityPanel */ @@ -112,11 +119,33 @@ public class DeckLegalityPanel extends javax.swing.JPanel { add(button); } + private boolean isMockCard(Card card) { + return card instanceof MockCard || card instanceof MockSplitCard; + } + public void validateDeck(Deck deck) { + // Non game GUI like Deck Editor works with Mock cards (fake cards with texts only), but validate must use + // real cards all the time. So convert it here before check. + + final Deck deckToValidate; + if (deck.getCards().stream().noneMatch(this::isMockCard) + && deck.getSideboard().stream().noneMatch(this::isMockCard)) { + // contains real cards, e.g. it's a game + deckToValidate = deck; + } else { + // contains mock cards, e.g. it's a Deck Editor + try { + deckToValidate = Deck.load(deck.getDeckCardLists(), true, false); + } catch (Exception ex) { + logger.error("Can't load real deck cards for validate: " + ex.getMessage(), ex); + return; + } + } + Arrays.stream(getComponents()) .filter(LegalityLabel.class::isInstance) .map(LegalityLabel.class::cast) - .forEach(label -> label.validateDeck(deck)); + .forEach(label -> label.validateDeck(deckToValidate)); } } diff --git a/Mage/src/main/java/mage/cards/decks/Deck.java b/Mage/src/main/java/mage/cards/decks/Deck.java index d99c97f648..1a5dd01bb2 100644 --- a/Mage/src/main/java/mage/cards/decks/Deck.java +++ b/Mage/src/main/java/mage/cards/decks/Deck.java @@ -145,7 +145,6 @@ public class Deck implements Serializable { deckCardLists.setName(name); for (Card card : cards) { - deckCardLists.getCards().add(new DeckCardInfo(card.getName(), card.getCardNumber(), card.getExpansionSetCode())); } for (Card card : sideboard) { diff --git a/Mage/src/main/java/mage/cards/mock/MockCard.java b/Mage/src/main/java/mage/cards/mock/MockCard.java index d4dbe07723..0a6b411344 100644 --- a/Mage/src/main/java/mage/cards/mock/MockCard.java +++ b/Mage/src/main/java/mage/cards/mock/MockCard.java @@ -14,7 +14,7 @@ import java.util.ArrayList; import java.util.List; /** - * Mock card for GUI (deck editor and panels) + * Mock card for GUI (deck editor and panels, contains only texts) * * @author North */