mirror of
https://github.com/correl/mage.git
synced 2025-01-11 19:13:02 +00:00
Optimized sql for deck editor
This commit is contained in:
parent
99ceeb5076
commit
6c3162f140
5 changed files with 95 additions and 57 deletions
|
@ -37,8 +37,8 @@ import javax.swing.*;
|
|||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static mage.client.dialog.PreferencesDialog.*;
|
||||
|
@ -299,6 +299,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
criteria.white(this.tbWhite.isSelected());
|
||||
criteria.colorless(this.tbColorless.isSelected());
|
||||
|
||||
// if you add new type filter then sync it with CardType
|
||||
if (this.tbLand.isSelected()) {
|
||||
criteria.types(CardType.LAND);
|
||||
}
|
||||
|
@ -320,8 +321,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
if (this.tbPlaneswalkers.isSelected()) {
|
||||
criteria.types(CardType.PLANESWALKER);
|
||||
}
|
||||
// criteria.types(CardType.TRIBAL);
|
||||
// criteria.types(CardType.CONSPIRACY);
|
||||
|
||||
if (this.tbCommon.isSelected()) {
|
||||
criteria.rarities(Rarity.COMMON);
|
||||
|
|
|
@ -1428,5 +1428,6 @@
|
|||
|Generate|TOK:M21|Zombie|||ZombieToken|
|
||||
|
||||
# JMP
|
||||
|Generate|TOK:JMP|Unicorn|||UnicornToken|
|
||||
|Generate|TOK:JMP|Dog|||WhiteDogToken|
|
||||
# Jumpstart uses tokens and emblems from M21 set,
|
||||
# TODO: check scryfall for JMP tokens after set's release
|
||||
|Generate|TOK:JMP|Unicorn|||UnicornToken|
|
|
@ -1,18 +1,17 @@
|
|||
|
||||
package mage.cards.repository;
|
||||
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.SelectArg;
|
||||
import com.j256.ormlite.stmt.Where;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public class CardCriteria {
|
||||
|
@ -177,6 +176,8 @@ public class CardCriteria {
|
|||
}
|
||||
|
||||
public void buildQuery(QueryBuilder qb) throws SQLException {
|
||||
optimize();
|
||||
|
||||
Where where = qb.where();
|
||||
where.eq("nightCard", false);
|
||||
where.eq("splitCardHalf", false);
|
||||
|
@ -249,37 +250,35 @@ public class CardCriteria {
|
|||
clausesCount++;
|
||||
}
|
||||
|
||||
if (!black || !blue || !green || !red || !white || !colorless) {
|
||||
int colorClauses = 0;
|
||||
if (black) {
|
||||
where.eq("black", true);
|
||||
colorClauses++;
|
||||
}
|
||||
if (blue) {
|
||||
where.eq("blue", true);
|
||||
colorClauses++;
|
||||
}
|
||||
if (green) {
|
||||
where.eq("green", true);
|
||||
colorClauses++;
|
||||
}
|
||||
if (red) {
|
||||
where.eq("red", true);
|
||||
colorClauses++;
|
||||
}
|
||||
if (white) {
|
||||
where.eq("white", true);
|
||||
colorClauses++;
|
||||
}
|
||||
if (colorless) {
|
||||
where.eq("black", false).eq("blue", false).eq("green", false).eq("red", false).eq("white", false);
|
||||
where.and(5);
|
||||
colorClauses++;
|
||||
}
|
||||
if (colorClauses > 0) {
|
||||
where.or(colorClauses);
|
||||
clausesCount++;
|
||||
}
|
||||
int colorClauses = 0;
|
||||
if (black) {
|
||||
where.eq("black", true);
|
||||
colorClauses++;
|
||||
}
|
||||
if (blue) {
|
||||
where.eq("blue", true);
|
||||
colorClauses++;
|
||||
}
|
||||
if (green) {
|
||||
where.eq("green", true);
|
||||
colorClauses++;
|
||||
}
|
||||
if (red) {
|
||||
where.eq("red", true);
|
||||
colorClauses++;
|
||||
}
|
||||
if (white) {
|
||||
where.eq("white", true);
|
||||
colorClauses++;
|
||||
}
|
||||
if (colorless) {
|
||||
where.eq("black", false).eq("blue", false).eq("green", false).eq("red", false).eq("white", false);
|
||||
where.and(5);
|
||||
colorClauses++;
|
||||
}
|
||||
if (colorClauses > 0) {
|
||||
where.or(colorClauses);
|
||||
clausesCount++;
|
||||
}
|
||||
|
||||
if (minCardNumber != Integer.MIN_VALUE) {
|
||||
|
@ -310,6 +309,38 @@ public class CardCriteria {
|
|||
}
|
||||
}
|
||||
|
||||
private CardCriteria optimize() {
|
||||
// remove rarity
|
||||
if (rarities.size() > 0) {
|
||||
List<Rarity> unusedRarities = new ArrayList<>(Arrays.asList(Rarity.values()));
|
||||
unusedRarities.removeAll(rarities);
|
||||
if (unusedRarities.isEmpty()) {
|
||||
rarities.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// remove color
|
||||
if (black && blue && green && red && white && colorless) {
|
||||
black = false;
|
||||
blue = false;
|
||||
green = false;
|
||||
red = false;
|
||||
white = false;
|
||||
colorless = false;
|
||||
}
|
||||
|
||||
// remove card type
|
||||
if (types.size() > 0) {
|
||||
List<CardType> unusedCardTypes = new ArrayList<>(Arrays.asList(CardType.values()));
|
||||
unusedCardTypes.removeAll(types);
|
||||
if (unusedCardTypes.stream().noneMatch(CardType::isIncludeInSearch)) {
|
||||
types.clear();
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -1,36 +1,39 @@
|
|||
package mage.constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import mage.MageObject;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author North
|
||||
*/
|
||||
public enum CardType {
|
||||
ARTIFACT("Artifact", true),
|
||||
CONSPIRACY("Conspiracy", false),
|
||||
CREATURE("Creature", true),
|
||||
ENCHANTMENT("Enchantment", true),
|
||||
INSTANT("Instant", false),
|
||||
LAND("Land", true),
|
||||
PHENOMENON("Phenomenon", false),
|
||||
PLANE("Plane", false),
|
||||
PLANESWALKER("Planeswalker", true),
|
||||
SCHEME("Scheme", false),
|
||||
SORCERY("Sorcery", false),
|
||||
TRIBAL("Tribal", false),
|
||||
VANGUARD("Vanguard", false);
|
||||
ARTIFACT("Artifact", true, true),
|
||||
CONSPIRACY("Conspiracy", false, false),
|
||||
CREATURE("Creature", true, true),
|
||||
ENCHANTMENT("Enchantment", true, true),
|
||||
INSTANT("Instant", false, true),
|
||||
LAND("Land", true, true),
|
||||
PHENOMENON("Phenomenon", false, false),
|
||||
PLANE("Plane", false, false),
|
||||
PLANESWALKER("Planeswalker", true, true),
|
||||
SCHEME("Scheme", false, false),
|
||||
SORCERY("Sorcery", false, true),
|
||||
TRIBAL("Tribal", false, false),
|
||||
VANGUARD("Vanguard", false, false);
|
||||
|
||||
private final String text;
|
||||
private final boolean permanentType;
|
||||
private final boolean includeInSearch; // types that can be searched/filtered by Deck Editor
|
||||
private final CardTypePredicate predicate;
|
||||
|
||||
CardType(String text, boolean permanentType) {
|
||||
CardType(String text, boolean permanentType, boolean includeInSearch) {
|
||||
this.text = text;
|
||||
this.permanentType = permanentType;
|
||||
this.includeInSearch = includeInSearch;
|
||||
this.predicate = new CardTypePredicate(this);
|
||||
}
|
||||
|
||||
|
@ -53,6 +56,10 @@ public enum CardType {
|
|||
return permanentType;
|
||||
}
|
||||
|
||||
public boolean isIncludeInSearch() {
|
||||
return includeInSearch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the card types from two lists of card types. Duplicates
|
||||
* are eliminated.
|
||||
|
|
|
@ -20,7 +20,7 @@ public final class WhiteDogToken extends TokenImpl {
|
|||
power = new MageInt(1);
|
||||
toughness = new MageInt(1);
|
||||
|
||||
availableImageSetCodes.addAll(Arrays.asList("M21", "JMP"));
|
||||
availableImageSetCodes.addAll(Arrays.asList("M21"));
|
||||
}
|
||||
|
||||
private WhiteDogToken(final WhiteDogToken token) {
|
||||
|
|
Loading…
Reference in a new issue