mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Cleaning up damage dealt by myk's enforcement of sorting info GuiChoose lists
This commit is contained in:
@@ -21,7 +21,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -5643,32 +5642,6 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static Comparator<Card> _nameComparator = new Comparator<Card>() {
|
||||
@Override
|
||||
public int compare(Card me, Card other) {
|
||||
if (me == other) {
|
||||
return 0;
|
||||
}
|
||||
if (null == other) {
|
||||
return 1;
|
||||
}
|
||||
if (me.getName() == other.getName()) {
|
||||
return 0;
|
||||
}
|
||||
if (null == me.getName()) {
|
||||
return -1;
|
||||
}
|
||||
return me.getName().compareTo(other.getName());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* For sorting lists of cards by name instead of by id
|
||||
*/
|
||||
public static final Comparator<Card> getNameComparator() {
|
||||
return _nameComparator;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ChooseGenericEffect extends SpellEffect {
|
||||
}
|
||||
SpellAbility chosenSA = null;
|
||||
if (p.isHuman()) {
|
||||
String choice = GuiChoose.one("Choose one", Lists.newArrayList(choices.values()));
|
||||
String choice = GuiChoose.one("Choose one", choices.values());
|
||||
chosenSA = AbilityFactory.getAbility(host.getSVar(choices.inverse().get(choice)), host);
|
||||
} else { //Computer AI
|
||||
chosenSA = AbilityFactory.getAbility(host.getSVar(sa.getParam("Choices").split(",")[0]), host);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge.card.ability.effects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,8 +27,7 @@ public class ManaReflectedEffect extends SpellEffect {
|
||||
AbilityManaPart ma = sa.getManaPart();
|
||||
sa.setUndoable(sa.isAbility() && sa.isUndoable());
|
||||
|
||||
final List<String> colors = new ArrayList<String>(
|
||||
CardUtil.getReflectableManaColors(sa, sa, new HashSet<String>(), new ArrayList<Card>()));
|
||||
final Collection<String> colors = CardUtil.getReflectableManaColors(sa, sa, new HashSet<String>(), new ArrayList<Card>());
|
||||
|
||||
final List<Player> tgtPlayers = getTargetPlayers(sa);
|
||||
for (final Player player : tgtPlayers) {
|
||||
@@ -62,7 +62,7 @@ public class ManaReflectedEffect extends SpellEffect {
|
||||
* a {@link forge.game.player.Player} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private static String generatedReflectedMana(final SpellAbility sa, final List<String> colors, final Player player) {
|
||||
private static String generatedReflectedMana(final SpellAbility sa, final Collection<String> colors, final Player player) {
|
||||
// Calculate generated mana here for stack description and resolving
|
||||
final int amount = sa.hasParam("Amount") ? AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("Amount"), sa) : 1;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ import forge.util.Expressions;
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public abstract class ReplacementEffect extends TriggerReplacementBase implements Comparable<ReplacementEffect> {
|
||||
public abstract class ReplacementEffect extends TriggerReplacementBase {
|
||||
|
||||
private ReplacementLayer layer = ReplacementLayer.None;
|
||||
|
||||
@@ -438,25 +438,4 @@ public abstract class ReplacementEffect extends TriggerReplacementBase implement
|
||||
public void setLayer(ReplacementLayer layer0) {
|
||||
this.layer = layer0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* used only for ordering, just sort by card
|
||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(ReplacementEffect other) {
|
||||
if (null == other) {
|
||||
return 1;
|
||||
}
|
||||
if (hostCard == other.hostCard) {
|
||||
return 0;
|
||||
}
|
||||
if (null == hostCard) {
|
||||
return -1;
|
||||
}
|
||||
if (null == other.hostCard) {
|
||||
return 1;
|
||||
}
|
||||
return hostCard.getName().compareTo(other.hostCard.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ import forge.game.player.Player;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class SpellAbility implements ISpellAbility, Comparable<SpellAbility> {
|
||||
public abstract class SpellAbility implements ISpellAbility {
|
||||
|
||||
// choices for constructor isPermanent argument
|
||||
private String description = "";
|
||||
@@ -1781,25 +1781,4 @@ public abstract class SpellAbility implements ISpellAbility, Comparable<SpellAbi
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* used for ordering in lists -- we just want to group by card
|
||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(SpellAbility other) {
|
||||
if (null == other) {
|
||||
return 1;
|
||||
}
|
||||
if (sourceCard == other.sourceCard) {
|
||||
return 0;
|
||||
}
|
||||
if (null == sourceCard) {
|
||||
return -1;
|
||||
}
|
||||
if (null == other.sourceCard) {
|
||||
return 1;
|
||||
}
|
||||
return sourceCard.getName().compareTo(other.sourceCard.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,20 +188,7 @@ public class GuiChoose {
|
||||
return objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience for getChoices(message, 0, 1, choices).
|
||||
*
|
||||
* @param <T>
|
||||
* is automatically inferred.
|
||||
* @param message
|
||||
* a {@link java.lang.String} object.
|
||||
* @param choices
|
||||
* a T object.
|
||||
* @return null if choices is missing, empty, or if the users' choices are
|
||||
* empty; otherwise, returns the first item in the List returned by
|
||||
* getChoices.
|
||||
* @see #getChoices(String, int, int, Object...)
|
||||
*/
|
||||
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
|
||||
public static <T> T sortedOneOrNone(final String message, final T[] choices, Comparator<T> comparer) {
|
||||
if ((choices == null) || (choices.length == 0)) {
|
||||
return null;
|
||||
@@ -210,6 +197,7 @@ public class GuiChoose {
|
||||
return choice.isEmpty() ? null : choice.get(0);
|
||||
} // getChoiceOptional(String,T...)
|
||||
|
||||
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
|
||||
public static <T> T sortedOneOrNone(final String message, final List<T> choices, Comparator<T> comparer) {
|
||||
if ((choices == null) || choices.isEmpty()) {
|
||||
return null;
|
||||
@@ -218,26 +206,15 @@ public class GuiChoose {
|
||||
return choice.isEmpty() ? null : choice.get(0);
|
||||
} // getChoiceOptional(String,T...)
|
||||
|
||||
// returned Object will never be null
|
||||
/**
|
||||
* <p>
|
||||
* getChoice.
|
||||
* </p>
|
||||
*
|
||||
* @param <T>
|
||||
* a T object.
|
||||
* @param message
|
||||
* a {@link java.lang.String} object.
|
||||
* @param choices
|
||||
* a T object.
|
||||
* @return a T object.
|
||||
*/
|
||||
|
||||
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
|
||||
public static <T> T sortedOne(final String message, final T[] choices, Comparator<T> comparer) {
|
||||
final List<T> choice = GuiChoose.sortedGetChoices(message, 1, 1, choices, comparer);
|
||||
assert choice.size() == 1;
|
||||
return choice.get(0);
|
||||
} // getChoice()
|
||||
|
||||
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
|
||||
public static <T> T sortedOne(final String message, final List<T> choices, Comparator<T> comparer) {
|
||||
if ((choices == null) || (choices.size() == 0)) {
|
||||
return null;
|
||||
@@ -247,18 +224,22 @@ public class GuiChoose {
|
||||
return choice.get(0);
|
||||
}
|
||||
|
||||
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
|
||||
public static <T> List<T> sortedNoneOrMany(final String message, final List<T> choices, Comparator<T> comparer) {
|
||||
return GuiChoose.sortedGetChoices(message, 0, choices.size(), choices, comparer);
|
||||
}
|
||||
|
||||
// If comparer is NULL, T must be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
|
||||
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
|
||||
public static <T> List<T> sortedGetChoices(final String message, final int min, final int max, final T[] choices, Comparator<T> comparer) {
|
||||
// You may create a copy of source array if callers expect the collection to be unchanged
|
||||
Arrays.sort(choices, comparer);
|
||||
final ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
|
||||
return getChoices(c);
|
||||
}
|
||||
|
||||
// If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine
|
||||
public static <T> List<T> sortedGetChoices(final String message, final int min, final int max, final List<T> choices, Comparator<T> comparer) {
|
||||
// You may create a copy of source list if callers expect the collection to be unchanged
|
||||
Collections.sort(choices, comparer);
|
||||
final ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
|
||||
return getChoices(c);
|
||||
|
||||
Reference in New Issue
Block a user