mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
GUI: deck legality improves:
* Added partly valid status for deck legality panel (if all cards are fine but user must add more cards to complete, see #6854); * Improved legality errors sorting (important errors visible at the top now, e.g. commander's errors);
This commit is contained in:
parent
9dfc6eed69
commit
e95b9f145c
20 changed files with 335 additions and 201 deletions
|
|
@ -58,15 +58,15 @@ public class Constructed extends DeckValidator {
|
|||
@Override
|
||||
public boolean validate(Deck deck) {
|
||||
boolean valid = true;
|
||||
invalid.clear();
|
||||
errorsList.clear();
|
||||
//20091005 - 100.2a
|
||||
if (deck.getCards().size() < getDeckMinSize()) {
|
||||
invalid.put("Deck", "Must contain at least " + getDeckMinSize() + " cards: has only " + deck.getCards().size() + " cards");
|
||||
addError(DeckValidatorErrorType.DECK_SIZE, "Deck", "Must contain at least " + getDeckMinSize() + " cards: has only " + deck.getCards().size() + " cards");
|
||||
valid = false;
|
||||
}
|
||||
//20130713 - 100.4a
|
||||
if (deck.getSideboard().size() > 15) {
|
||||
invalid.put("Sideboard", "Must contain no more than 15 cards : has " + deck.getSideboard().size() + " cards");
|
||||
addError(DeckValidatorErrorType.DECK_SIZE, "Sideboard", "Must contain no more than 15 cards : has " + deck.getSideboard().size() + " cards");
|
||||
valid = false;
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ public class Constructed extends DeckValidator {
|
|||
|
||||
for (String bannedCard : banned) {
|
||||
if (counts.containsKey(bannedCard)) {
|
||||
invalid.put(bannedCard, "Banned");
|
||||
addError(DeckValidatorErrorType.BANNED, "Banned", bannedCard);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ public class Constructed extends DeckValidator {
|
|||
if (counts.containsKey(restrictedCard)) {
|
||||
int count = counts.get(restrictedCard);
|
||||
if (count > 1) {
|
||||
invalid.put(restrictedCard, "Restricted: " + count);
|
||||
addError(DeckValidatorErrorType.OTHER, restrictedCard, "Restricted amount: " + count);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -142,8 +142,8 @@ public class Constructed extends DeckValidator {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (!legal && !invalid.containsKey(card.getName())) {
|
||||
invalid.put(card.getName(), "Invalid rarity: " + card.getRarity());
|
||||
if (!legal && !errorsListContainsGroup(card.getName())) {
|
||||
addError(DeckValidatorErrorType.OTHER, card.getName(), "Invalid rarity: " + card.getRarity());
|
||||
}
|
||||
return legal;
|
||||
}
|
||||
|
|
@ -180,8 +180,8 @@ public class Constructed extends DeckValidator {
|
|||
legal = true;
|
||||
}
|
||||
|
||||
if (!legal && !invalid.containsKey(card.getName())) {
|
||||
invalid.put(card.getName(), "Invalid set: " + card.getExpansionSetCode());
|
||||
if (!legal && !errorsListContainsGroup(card.getName())) {
|
||||
addError(DeckValidatorErrorType.WRONG_SET, card.getName(), "Invalid set: " + card.getExpansionSetCode());
|
||||
}
|
||||
return legal;
|
||||
}
|
||||
|
|
@ -192,11 +192,11 @@ public class Constructed extends DeckValidator {
|
|||
if (entry.getValue() > maxCopies
|
||||
&& !basicLandNames.contains(entry.getKey())
|
||||
&& !anyNumberCardsAllowed.contains(entry.getKey())) {
|
||||
invalid.put(entry.getKey(), "Too many: " + entry.getValue());
|
||||
addError(DeckValidatorErrorType.OTHER, entry.getKey(), "Too many: " + entry.getValue());
|
||||
valid = false;
|
||||
}
|
||||
if (entry.getValue() > 7 && entry.getKey().equals("Seven Dwarves")) {
|
||||
invalid.put(entry.getKey(), "Too many: " + entry.getValue());
|
||||
addError(DeckValidatorErrorType.OTHER, entry.getKey(), "Too many: " + entry.getValue());
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ package mage.cards.decks;
|
|||
import mage.cards.Card;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -14,8 +13,7 @@ public abstract class DeckValidator implements Serializable {
|
|||
|
||||
protected String name;
|
||||
protected String shortName;
|
||||
|
||||
protected Map<String, String> invalid = new HashMap<>();
|
||||
protected List<DeckValidatorError> errorsList = new ArrayList<>();
|
||||
|
||||
public DeckValidator(String name) {
|
||||
setName(name);
|
||||
|
|
@ -49,8 +47,62 @@ public abstract class DeckValidator implements Serializable {
|
|||
this.shortName = shortName;
|
||||
}
|
||||
|
||||
public Map<String, String> getInvalid() {
|
||||
return invalid;
|
||||
public List<DeckValidatorError> getErrorsList() {
|
||||
return this.errorsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get errors list sorted by error type and texts
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<DeckValidatorError> getErrorsListSorted() {
|
||||
List<DeckValidatorError> list = new ArrayList<>(this.getErrorsList());
|
||||
|
||||
Collections.sort(list, new Comparator<DeckValidatorError>() {
|
||||
@Override
|
||||
public int compare(DeckValidatorError e1, DeckValidatorError e2) {
|
||||
int res = 0;
|
||||
|
||||
// sort by error type
|
||||
Integer order1 = e1.getErrorType().getSortOrder();
|
||||
Integer order2 = e2.getErrorType().getSortOrder();
|
||||
res = order2.compareTo(order1);
|
||||
|
||||
// sort by group
|
||||
if (res != 0) {
|
||||
res = e2.getGroup().compareTo(e1.getGroup());
|
||||
}
|
||||
|
||||
// sort by message
|
||||
if (res != 0) {
|
||||
res = e2.getMessage().compareTo(e1.getMessage());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public String getErrorsListInfo() {
|
||||
// for tests
|
||||
return this.errorsList.stream()
|
||||
.map(e -> e.getGroup() + "=" + e.getMessage())
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
public void addError(DeckValidatorErrorType errorType, String group, String message) {
|
||||
this.errorsList.add(new DeckValidatorError(errorType, group, message));
|
||||
}
|
||||
|
||||
public boolean errorsListContainsGroup(String group) {
|
||||
return this.errorsList.stream().anyMatch(e -> e.getGroup().equals(group));
|
||||
}
|
||||
|
||||
public boolean isPartlyValid() {
|
||||
return errorsList.size() == 0 || !errorsList.stream().anyMatch(e -> !e.getErrorType().isPartlyLegal());
|
||||
}
|
||||
|
||||
protected void countCards(Map<String, Integer> counts, Collection<Card> cards) {
|
||||
|
|
|
|||
29
Mage/src/main/java/mage/cards/decks/DeckValidatorError.java
Normal file
29
Mage/src/main/java/mage/cards/decks/DeckValidatorError.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package mage.cards.decks;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class DeckValidatorError {
|
||||
|
||||
private final DeckValidatorErrorType errorType;
|
||||
private final String group;
|
||||
private final String message;
|
||||
|
||||
public DeckValidatorError(DeckValidatorErrorType errorType, String group, String message) {
|
||||
this.errorType = errorType;
|
||||
this.group = group;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public DeckValidatorErrorType getErrorType() {
|
||||
return this.errorType;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return this.group;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package mage.cards.decks;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public enum DeckValidatorErrorType {
|
||||
|
||||
PRIMARY(false, 10), // first errors to show (e.g. missing commander)
|
||||
DECK_SIZE(true, 20), // wrong deck size (deck must be legal while building)
|
||||
BANNED(false, 30),
|
||||
WRONG_SET(false, 40),
|
||||
OTHER(false, 50);
|
||||
|
||||
private final boolean partlyLegal; // for deck legality panel: is it partly legal (e.g. show deck legal even without full deck size)
|
||||
private final int sortOrder; // errors list sort order from small to big
|
||||
|
||||
DeckValidatorErrorType(boolean partlyLegal, int sortOrder) {
|
||||
this.partlyLegal = partlyLegal;
|
||||
this.sortOrder = sortOrder;
|
||||
}
|
||||
|
||||
public boolean isPartlyLegal() {
|
||||
return this.partlyLegal;
|
||||
}
|
||||
|
||||
public int getSortOrder() {
|
||||
return this.sortOrder;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue