From 1b3445f3257556cce4f72f59a8f60c1ebfeffcdb Mon Sep 17 00:00:00 2001 From: jendave Date: Sun, 23 Oct 2011 06:57:37 +0000 Subject: [PATCH] Fix proxy generator cardlist --- src/main/java/forge/deck/DeckManager.java | 7 ++ src/main/java/forge/item/ItemPoolView.java | 97 +++++++++++++++++++++- src/main/resources/proxy-template.ftl | 6 +- 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/src/main/java/forge/deck/DeckManager.java b/src/main/java/forge/deck/DeckManager.java index 8e2c61b10e7..0f1ae1dc9a3 100644 --- a/src/main/java/forge/deck/DeckManager.java +++ b/src/main/java/forge/deck/DeckManager.java @@ -666,12 +666,19 @@ public class DeckManager { //System.out.println(card.getSets().get(card.getSets().size() - 1).URL); nameList.add(card.getName()); } + + Map map = new HashMap(); + for (Entry entry : d.getMain().getOrderedList()) { + map.put(entry.getKey().getName(), entry.getValue()); + System.out.println(entry.getValue() + " " + entry.getKey().getName()); + } root.put("urls", list); root.put("cardBorder", cardBorder); root.put("height", height); root.put("width", width); root.put("cardlistWidth", width - 11); root.put("nameList", nameList); + root.put("cardList", map); /* Merge data-model with template */ //StringWriter sw = new StringWriter(); diff --git a/src/main/java/forge/item/ItemPoolView.java b/src/main/java/forge/item/ItemPoolView.java index 8a65e160bce..344974a41df 100644 --- a/src/main/java/forge/item/ItemPoolView.java +++ b/src/main/java/forge/item/ItemPoolView.java @@ -21,59 +21,139 @@ import net.slightlymagic.braids.util.lambda.Lambda1; public class ItemPoolView implements Iterable> { // Field Accessors for select/aggregate operations with filters. + /** + * + */ public final Lambda1> fnToCard = new Lambda1>() { @Override public CardRules apply(final Entry from) { T item = from.getKey(); - return item instanceof CardPrinted ? ((CardPrinted) item).getCard() : null; + return item instanceof CardPrinted ? ((CardPrinted) item).getCard() : null; } }; + + /** + * + */ public final Lambda1> fnToPrinted = new Lambda1>() { @Override public T apply(final Entry from) { return from.getKey(); } }; + + /** + * + */ public final Lambda1> fnToCardName = new Lambda1>() { @Override public String apply(final Entry from) { return from.getKey().getName(); } }; + + /** + * + */ public final Lambda1> fnToCount = new Lambda1>() { @Override public Integer apply(final Entry from) { return from.getValue(); } }; // Constructors + /** + * + * ItemPoolView. + * @param cls a Class + */ public ItemPoolView(final Class cls) { cards = new Hashtable(); myClass = cls; } + + /** + * + * ItemPoolView. + * @param inMap a Map + * @param cls a Class + */ public ItemPoolView(final Map inMap, final Class cls) { cards = inMap; myClass = cls; } // Data members + /** + * + */ protected Map cards; + /** + * + */ protected final Class myClass; // class does not keep this in runtime by itself - // same thing as above, it was copied to provide sorting (needed by table views in deck editors) + // same thing as above, it was copied to provide sorting (needed by table views in deck editors) + /** + * + */ protected List> cardsListOrdered = new ArrayList>(); + + /** + * + */ protected boolean isListInSync = false; + /** + * iterator. + * @return Iterator> + */ @Override public final Iterator> iterator() { return cards.entrySet().iterator(); } // Cards read only operations + /** + * + * contains. + * @param card a T + * @return boolean + */ public final boolean contains(final T card) { if (cards == null) { return false; } return cards.containsKey(card); } + + /** + * + * count. + * @param card a T + * @return int + */ public final int count(final T card) { if (cards == null) { return 0; } Integer boxed = cards.get(card); return boxed == null ? 0 : boxed.intValue(); } + + /** + * + * countAll. + * @return int + */ public final int countAll() { int result = 0; if (cards != null) { for (Integer n : cards.values()) { result += n; } } return result; } + + /** + * + * countDistinct. + * @return int + */ public final int countDistinct() { return cards.size(); } + + /** + * + * isEmpty. + * @return boolean + */ public final boolean isEmpty() { return cards == null || cards.isEmpty(); } + /** + * + * getOrderedList. + * @return List> + */ public final List> getOrderedList() { if (!isListInSync) { rebuildOrderedList(); } return cardsListOrdered; @@ -89,6 +169,11 @@ public class ItemPoolView implements Iterable + */ public final List toFlatList() { List result = new ArrayList(); for (Entry e : this) { @@ -97,11 +182,15 @@ public class ItemPoolView implements Iterable e : this) { - if ( e.getKey() instanceof CardPrinted ) - { + if (e.getKey() instanceof CardPrinted) { for (int i = 0; i < e.getValue(); i++) { result.add(((CardPrinted) e.getKey()).toForgeCard()); } diff --git a/src/main/resources/proxy-template.ftl b/src/main/resources/proxy-template.ftl index 813536fda48..73e58c7f819 100644 --- a/src/main/resources/proxy-template.ftl +++ b/src/main/resources/proxy-template.ftl @@ -21,9 +21,9 @@
- <#list nameList as name> - ${name}
- +<#list cardList?keys as key> + ${cardList[key]} ${key}
+