now we depend on apache.commons.io

updated set aliases
more predicates for good use
deckeditorbase concept preview
This commit is contained in:
Maxmtg
2011-08-28 15:33:26 +00:00
parent b67e86c573
commit fc95a74ada
5 changed files with 137 additions and 10 deletions

1
.gitattributes vendored
View File

@@ -9543,6 +9543,7 @@ src/main/java/forge/GuiQuestFilter.java svneol=native#text/plain
src/main/java/forge/Gui_BoosterDraft.java svneol=native#text/plain src/main/java/forge/Gui_BoosterDraft.java svneol=native#text/plain
src/main/java/forge/Gui_CardShop.java svneol=native#text/plain src/main/java/forge/Gui_CardShop.java svneol=native#text/plain
src/main/java/forge/Gui_DeckEditor.java svneol=native#text/plain src/main/java/forge/Gui_DeckEditor.java svneol=native#text/plain
src/main/java/forge/Gui_DeckEditorBase.java -text
src/main/java/forge/Gui_DeckEditor_Menu.java svneol=native#text/plain src/main/java/forge/Gui_DeckEditor_Menu.java svneol=native#text/plain
src/main/java/forge/Gui_DownloadPictures_LQ.java svneol=native#text/plain src/main/java/forge/Gui_DownloadPictures_LQ.java svneol=native#text/plain
src/main/java/forge/Gui_DownloadPrices.java svneol=native#text/plain src/main/java/forge/Gui_DownloadPrices.java svneol=native#text/plain

View File

@@ -587,6 +587,11 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.0.1</version> <version>3.0.1</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency> <dependency>
<groupId>commons-discovery</groupId> <groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId> <artifactId>commons-discovery</artifactId>

View File

@@ -23,7 +23,7 @@ Index:19|Code2:WL|Code3:WTH|Name:Weatherlight
Index:20|Code2:TE|Code3:TMP|Name:Tempest Index:20|Code2:TE|Code3:TMP|Name:Tempest
Index:21|Code2:SH|Code3:STH|Name:Stronghold Index:21|Code2:SH|Code3:STH|Name:Stronghold
Index:22|Code2:EX|Code3:EXO|Name:Exodus Index:22|Code2:EX|Code3:EXO|Name:Exodus
Index:23|Code2:P2|Code3:PO2|Name:Portal Second Age Index:23|Code2:P2|Code3:PO2|Name:Portal Second Age|Alias:P02
Index:24|Code2:US|Code3:USG|Name:Urza's Saga Index:24|Code2:US|Code3:USG|Name:Urza's Saga
Index:25|Code2:UL|Code3:ULG|Name:Urza's Legacy Index:25|Code2:UL|Code3:ULG|Name:Urza's Legacy
Index:26|Code2:6E|Code3:6ED|Name:Classic (Sixth Edition) Index:26|Code2:6E|Code3:6ED|Name:Classic (Sixth Edition)
@@ -68,7 +68,7 @@ Index:60|Code2:10E|Code3:10E|Name:Core Set - Tenth Edition
Index:61|Code2:LRW|Code3:LRW|Name:Lorwyn Index:61|Code2:LRW|Code3:LRW|Name:Lorwyn
Index:62|Code2:MOR|Code3:MOR|Name:Morningtide Index:62|Code2:MOR|Code3:MOR|Name:Morningtide
Index:63|Code2:SHM|Code3:SHM|Name:Shadowmoor Index:63|Code2:SHM|Code3:SHM|Name:Shadowmoor
Index:64|Code2:EVE|Code3:EVE|Name:Eventide Index:64|Code2:EVE|Code3:EVE|Name:Eventide|Alias:EVT
Index:65|Code2:ALA|Code3:ALA|Name:Shards of Alara Index:65|Code2:ALA|Code3:ALA|Name:Shards of Alara
Index:66|Code2:CFX|Code3:CFX|Name:Conflux|Alias:CON Index:66|Code2:CFX|Code3:CFX|Name:Conflux|Alias:CON
Index:67|Code2:ARB|Code3:ARB|Name:Alara Reborn Index:67|Code2:ARB|Code3:ARB|Name:Alara Reborn

View File

@@ -0,0 +1,75 @@
package forge;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import net.slightlymagic.maxmtg.Predicate;
import forge.card.CardCoreType;
import forge.card.CardRules;
import forge.card.CardRules.Predicates;
import forge.card.CardPoolView;
public class Gui_DeckEditorBase extends JFrame {
private static final long serialVersionUID = -401223933343539977L;
//public JCheckBox whiteCheckBox = new GuiFilterCheckBox("white", "White");
public JCheckBox whiteCheckBox = new JCheckBox("W", true);
public JCheckBox blueCheckBox = new JCheckBox("U", true);
public JCheckBox blackCheckBox = new JCheckBox("B", true);
public JCheckBox redCheckBox = new JCheckBox("R", true);
public JCheckBox greenCheckBox = new JCheckBox("G", true);
public JCheckBox colorlessCheckBox = new JCheckBox("C", true);
public JCheckBox landCheckBox = new JCheckBox("Land", true);
public JCheckBox creatureCheckBox = new JCheckBox("Creature", true);
public JCheckBox sorceryCheckBox = new JCheckBox("Sorcery", true);
public JCheckBox instantCheckBox = new JCheckBox("Instant", true);
public JCheckBox planeswalkerCheckBox = new JCheckBox("Planeswalker", true);
public JCheckBox artifactCheckBox = new JCheckBox("Artifact", true);
public JCheckBox enchantmentCheckBox = new JCheckBox("Enchant", true);
public static String getStats(CardPoolView deck) {
int total = deck.countAll();
int creature = CardRules.Predicates.Presets.isCreature.aggregate(deck, CardPoolView.fnToCard, CardPoolView.fnToCount);
int land = CardRules.Predicates.Presets.isLand.aggregate(deck, CardPoolView.fnToCard, CardPoolView.fnToCount);
StringBuffer show = new StringBuffer();
show.append("Total - ").append(total).append(", Creatures - ").append(creature).append(", Land - ")
.append(land);
String[] color = Constant.Color.onlyColors;
List<Predicate<CardRules>> predicates = CardRules.Predicates.Presets.colors;
for (int i = 0; i < color.length; ++i) {
show.append(String.format(", %s - %d", color[i], predicates.get(i).count(deck, CardPoolView.fnToCard)));
}
return show.toString();
}// getStats()
public final Predicate<CardRules> buildFilter() {
List<Predicate<CardRules>> colors = new ArrayList<Predicate<CardRules>>();
if (whiteCheckBox.isSelected()) { colors.add(CardRules.Predicates.Presets.isWhite); }
if (blueCheckBox.isSelected()) { colors.add(CardRules.Predicates.Presets.isBlue); }
if (blackCheckBox.isSelected()) { colors.add(CardRules.Predicates.Presets.isBlack); }
if (redCheckBox.isSelected()) { colors.add(CardRules.Predicates.Presets.isRed); }
if (greenCheckBox.isSelected()) { colors.add(CardRules.Predicates.Presets.isGreen); }
if (colorlessCheckBox.isSelected()) { colors.add(CardRules.Predicates.Presets.isColorless); }
Predicate<CardRules> filterByColor = colors.size() == 6 ? Predicate.getTrue(CardRules.class) : Predicate.or(colors);
List<Predicate<CardRules>> types = new ArrayList<Predicate<CardRules>>();
if (landCheckBox.isSelected()) { types.add(CardRules.Predicates.Presets.isLand); }
if (creatureCheckBox.isSelected()) { types.add(CardRules.Predicates.Presets.isCreature); }
if (sorceryCheckBox.isSelected()) { types.add(CardRules.Predicates.Presets.isSorcery); }
if (instantCheckBox.isSelected()) { types.add(CardRules.Predicates.Presets.isInstant); }
if (planeswalkerCheckBox.isSelected()) { types.add(CardRules.Predicates.Presets.isPlaneswalker); }
if (artifactCheckBox.isSelected()) { types.add(CardRules.Predicates.Presets.isArtifact); }
if (enchantmentCheckBox.isSelected()) { types.add(CardRules.Predicates.Presets.isEnchantment); }
Predicate<CardRules> filterByType = colors.size() == 7 ? Predicate.getTrue(CardRules.class) : Predicate.or(types);
return Predicate.and(filterByColor, filterByType);
}
}

View File

@@ -117,7 +117,7 @@ public abstract class Predicate<T> {
} }
// Random - algorithm adapted from Braid's GeneratorFunctions // Random - algorithm adapted from Braid's GeneratorFunctions
public final T random(final Iterable<T> source) { // public final T random(final Iterable<T> source) {
int n = 0; int n = 0;
T candidate = null; T candidate = null;
for (T item : source) { for (T item : source) {
@@ -135,6 +135,28 @@ public abstract class Predicate<T> {
} }
return candidate; return candidate;
} }
// Get several random values
// should improve to make 1 pass over source and track N candidates at once
public final List<T> random(final Iterable<T> source, final int count) {
List<T> result = new ArrayList<T>();
for (int i = 0; i < count; ++i) {
T toAdd = random(source);
if (toAdd == null) { break; }
result.add(toAdd);
}
return result;
}
public final <U> List<U> random(final Iterable<U> source, final Lambda1<T, U> accessor, final int count) {
List<U> result = new ArrayList<U>();
for (int i = 0; i < count; ++i) {
U toAdd = random(source, accessor);
if (toAdd == null) { break; }
result.add(toAdd);
}
return result;
}
// Static builder methods - they choose concrete implementation by themselves // Static builder methods - they choose concrete implementation by themselves
public static <T> Predicate<T> not(final Predicate<T> operand1) { return new Not<T>(operand1); } public static <T> Predicate<T> not(final Predicate<T> operand1) { return new Not<T>(operand1); }
public static <T> Predicate<T> compose(final Predicate<T> operand1, public static <T> Predicate<T> compose(final Predicate<T> operand1,
@@ -142,14 +164,14 @@ public abstract class Predicate<T> {
{ {
return new Node<T>(operand1, operator, operand2); return new Node<T>(operand1, operator, operand2);
} }
public static <T> Predicate<T> and(final Predicate<T> operand1, final Predicate<T> operand2) { // Predefined operators: and, or
return new NodeAnd<T>(operand1, operand2); public static <T> Predicate<T> and(final Predicate<T> operand1, final Predicate<T> operand2) { return new NodeAnd<T>(operand1, operand2); }
}
public static <T> Predicate<T> and(final Iterable<Predicate<T>> operand) { return new MultiNodeAnd<T>(operand); } public static <T> Predicate<T> and(final Iterable<Predicate<T>> operand) { return new MultiNodeAnd<T>(operand); }
public static <T> Predicate<T> or(final Predicate<T> operand1, final Predicate<T> operand2) { public static <T, U> Predicate<T> and(final Predicate<T> operand1, final Predicate<U> operand2, Lambda1<U, T> bridge) { return new NodeAndBridged<T, U>(operand1, operand2, bridge); }
return new NodeOr<T>(operand1, operand2);
} public static <T> Predicate<T> or(final Predicate<T> operand1, final Predicate<T> operand2) { return new NodeOr<T>(operand1, operand2); }
public static <T> Predicate<T> or(final Iterable<Predicate<T>> operand) { return new MultiNodeOr<T>(operand); } public static <T> Predicate<T> or(final Iterable<Predicate<T>> operand) { return new MultiNodeOr<T>(operand); }
public static <T, U> Predicate<T> or(final Predicate<T> operand1, final Predicate<U> operand2, Lambda1<U, T> bridge) { return new NodeOrBridged<T, U>(operand1, operand2, bridge); }
// Concrete implementations // Concrete implementations
// unary operators // unary operators
@@ -197,6 +219,30 @@ public abstract class Predicate<T> {
@Override public boolean isTrue(final T card) { return filter1.isTrue(card) && filter2.isTrue(card); } @Override public boolean isTrue(final T card) { return filter1.isTrue(card) && filter2.isTrue(card); }
} }
// Bridged OR and AND
protected static final class NodeOrBridged<T,U> extends Predicate<T> {
private final Predicate<T> filter1;
private final Predicate<U> filter2;
private final Lambda1<U, T> bridge;
public NodeOrBridged(final Predicate<T> operand1, final Predicate<U> operand2, final Lambda1<U, T> accessor) {
filter1 = operand1;
filter2 = operand2;
bridge = accessor;
}
@Override public boolean isTrue(final T card) { return filter1.isTrue(card) || filter2.isTrue(bridge.apply(card)); }
}
protected static final class NodeAndBridged<T,U> extends Predicate<T> {
private final Predicate<T> filter1;
private final Predicate<U> filter2;
private final Lambda1<U, T> bridge;
public NodeAndBridged(final Predicate<T> operand1, final Predicate<U> operand2, final Lambda1<U, T> accessor) {
filter1 = operand1;
filter2 = operand2;
bridge = accessor;
}
@Override public boolean isTrue(final T card) { return filter1.isTrue(card) && filter2.isTrue(bridge.apply(card)); }
}
// multi-operand operators // multi-operand operators
protected abstract static class MultiNode<T> extends Predicate<T> { protected abstract static class MultiNode<T> extends Predicate<T> {
protected final Iterable<Predicate<T>> operands; protected final Iterable<Predicate<T>> operands;