Commit 2f9fb96d authored by Peter Patel-Schneider's avatar Peter Patel-Schneider

use Iterators instead of Lists where possible in manipulateCardList

parent 3749f2a5
......@@ -285,7 +285,7 @@ public class GuiChoose {
return null;
}
public static List<CardView> manipulateCardList(final CMatchUI gui, final String title, final List<CardView> cards, final List<CardView> manipulable,
public static List<CardView> manipulateCardList(final CMatchUI gui, final String title, final Iterable<CardView> cards, final Iterable<CardView> manipulable,
final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
final Callable<List<CardView>> callable = new Callable<List<CardView>>() {
@Override
......
......@@ -1004,7 +1004,7 @@ public final class CMatchUI
}
@Override
public List<CardView> manipulateCardList(final String title, final List<CardView> cards, final List<CardView> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
public List<CardView> manipulateCardList(final String title, final Iterable<CardView> cards, final Iterable<CardView> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
return GuiChoose.manipulateCardList(this, title, cards, manipulable, toTop, toBottom, toAnywhere);
}
......
......@@ -59,11 +59,12 @@ public class ListCardArea extends FloatingCardArea {
setOpaque(false);
}
public static ListCardArea show(final CMatchUI matchUI, final String title0, final List<CardView> cardList0, final List<CardView> moveableCards0, final boolean toTop0, final boolean toBottom0, final boolean toAnywhere0) {
public static ListCardArea show(final CMatchUI matchUI, final String title0, final Iterable<CardView> cardList0, final Iterable<CardView> moveableCards0, final boolean toTop0, final boolean toBottom0, final boolean toAnywhere0) {
if (storedArea==null) {
storedArea = new ListCardArea(matchUI);
}
cardList = new ArrayList<CardView>(cardList0);
cardList = new ArrayList<CardView>();
for ( CardView cv : cardList0 ) { cardList.add(cv) ; }
moveableCards = new ArrayList<CardView>(); // make sure moveable cards are in cardlist
for ( CardView card : moveableCards0 ) {
if ( cardList.contains(card) ) {
......
......@@ -521,7 +521,7 @@ public class MatchController extends AbstractGuiGame {
}
@Override
public List<CardView> manipulateCardList(final String title, final List<CardView> cards, final List<CardView> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
public List<CardView> manipulateCardList(final String title, final Iterable<CardView> cards, final Iterable<CardView> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
System.err.println("Not implemented yet - should never be called");
return null;
}
......
......@@ -149,7 +149,7 @@ public interface IGuiGame {
List<GameEntityView> chooseEntitiesForEffect(String title, List<? extends GameEntityView> optionList, int min, int max, DelayedReveal delayedReveal);
// show a list of cards and allow some of them to be moved around and return new list
List<CardView> manipulateCardList(String title, final List<CardView> cards, final List<CardView> manipulable, boolean toTop, boolean toBottom, boolean toAnywhere);
List<CardView> manipulateCardList(String title, final Iterable<CardView> cards, final Iterable<CardView> manipulable, boolean toTop, boolean toBottom, boolean toAnywhere);
void setCard(CardView card);
void setPlayerAvatar(LobbyPlayer player, IHasIcon ihi);
......
......@@ -68,7 +68,7 @@ public enum ProtocolMethod {
sideboard (Mode.SERVER, List.class, CardPool.class, CardPool.class),
chooseSingleEntityForEffect(Mode.SERVER, GameEntityView.class, String.class, List.class, DelayedReveal.class, Boolean.TYPE),
chooseEntitiesForEffect(Mode.SERVER, GameEntityView.class, String.class, List.class, Integer.TYPE, Integer.TYPE, DelayedReveal.class),
manipulateCardList (Mode.SERVER, List.class, String.class, List.class, List.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE),
manipulateCardList (Mode.SERVER, List.class, String.class, Iterable.class, Iterable.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE),
setCard (Mode.SERVER, Void.TYPE, CardView.class),
// TODO case "setPlayerAvatar":
openZones (Mode.SERVER, Boolean.TYPE, Collection/*ZoneType*/.class, Map/*PlayerView,Object*/.class),
......
......@@ -249,7 +249,7 @@ public class NetGuiGame extends AbstractGuiGame {
}
@Override
public List<CardView> manipulateCardList(final String title, final List<CardView> cards, final List<CardView> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
public List<CardView> manipulateCardList(final String title, final Iterable<CardView> cards, final Iterable<CardView> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
return sendAndWait(ProtocolMethod.manipulateCardList, title, cards, manipulable, toTop, toBottom, toAnywhere);
}
......
......@@ -737,25 +737,12 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
}
}
public List<Card> manipulateCardList(final String title, final List<Card> cards, final List<Card> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
ArrayList<CardView> cardViews = new ArrayList<CardView>();
for ( Card c : cards ) { cardViews.add(c.getView()); }
ArrayList<CardView> manipulableViews = new ArrayList<CardView>();
for ( Card c : manipulable ) { manipulableViews.add(c.getView()); }
Iterable<CardView> result = getGui().manipulateCardList(title, cardViews, manipulableViews, toTop, toBottom, toAnywhere);
List<Card> resultCards = new ArrayList<Card>();
for ( CardView cv : result ) {
for ( Card card : cards ) {
if ( cv == card.getView() ) {
resultCards.add(card);
break;
}
}
}
return resultCards;
public List<Card> manipulateCardList(final String title, final Iterable<Card> cards, final Iterable<Card> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
Iterable<CardView> result = getGui().manipulateCardList(title, CardView.getCollection(cards), CardView.getCollection(manipulable), toTop, toBottom, toAnywhere);
return game.getCardList(result);
}
public ImmutablePair<CardCollection, CardCollection> arrangeForMove(final String title, final List<Card> cards, final List<Card> manipulable, final boolean topOK, final boolean bottomOK) {
public ImmutablePair<CardCollection, CardCollection> arrangeForMove(final String title, final FCollectionView<Card> cards, final List<Card> manipulable, final boolean topOK, final boolean bottomOK) {
List<Card> result = manipulateCardList("Move cards to top or bottom of library", cards, manipulable, topOK, bottomOK, false);
CardCollection toBottom = new CardCollection();
CardCollection toTop = new CardCollection();
......@@ -778,10 +765,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
tempShowCards(topN);
if ( FModel.getPreferences().getPrefBoolean(FPref.UI_SELECT_FROM_CARD_DISPLAYS) &&
(!GuiBase.getInterface().isLibgdxPort()) ) {
ArrayList<Card> cardList = new ArrayList<Card>(); // pfps there must be a better way
for (final Card card : player.getCardsIn(ZoneType.Library)) {
cardList.add(card);
}
CardCollectionView cardList = player.getCardsIn(ZoneType.Library);
ImmutablePair<CardCollection, CardCollection> result =
arrangeForMove("Move cards to top or bottom of library", cardList, topN, true, true);
toTop = result.getLeft();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment