mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
removed list or items from CardPool that had to be kept in sync with the main map, since no other class but ItemManagerModel used it (I wanted to do that for too long already!)
This commit is contained in:
@@ -32,6 +32,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
|
|
||||||
import forge.card.CardDb;
|
import forge.card.CardDb;
|
||||||
@@ -209,7 +211,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> writeCardPool(final ItemPoolView<PaperCard> pool) {
|
private static List<String> writeCardPool(final ItemPoolView<PaperCard> pool) {
|
||||||
final List<Entry<PaperCard, Integer>> main2sort = pool.getOrderedList();
|
List<Entry<PaperCard, Integer>> main2sort = Lists.newArrayList(pool);
|
||||||
Collections.sort(main2sort, ItemPoolSorter.BY_NAME_THEN_SET);
|
Collections.sort(main2sort, ItemPoolSorter.BY_NAME_THEN_SET);
|
||||||
final List<String> out = new ArrayList<String>();
|
final List<String> out = new ArrayList<String>();
|
||||||
for (final Entry<PaperCard, Integer> e : main2sort) {
|
for (final Entry<PaperCard, Integer> e : main2sort) {
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ import forge.item.InventoryItem;
|
|||||||
*/
|
*/
|
||||||
public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors here
|
// Constructors here
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -47,7 +45,6 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
super(cls);
|
super(cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(final ItemPoolView<Tin> from, final Class<Tout> clsHint) {
|
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> createFrom(final ItemPoolView<Tin> from, final Class<Tout> clsHint) {
|
||||||
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
final ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
|
||||||
@@ -113,7 +110,6 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.items.put(item, Integer.valueOf(this.count(item) + amount));
|
this.items.put(item, Integer.valueOf(this.count(item) + amount));
|
||||||
this.isListInSync = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,7 +127,6 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
this.add((T) cr);
|
this.add((T) cr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.isListInSync = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,7 +145,6 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
this.add((T) e.getKey(), e.getValue());
|
this.add((T) e.getKey(), e.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.isListInSync = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,7 +177,6 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
} else {
|
} else {
|
||||||
this.items.put(item, count - amount);
|
this.items.put(item, count - amount);
|
||||||
}
|
}
|
||||||
this.isListInSync = false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +216,5 @@ public class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
|
|||||||
*/
|
*/
|
||||||
public void clear() {
|
public void clear() {
|
||||||
this.items.clear();
|
this.items.clear();
|
||||||
this.isListInSync = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,14 +84,6 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
private final Class<T> myClass; // class does not keep this in runtime by
|
private final Class<T> myClass; // class does not keep this in runtime by
|
||||||
// itself
|
// itself
|
||||||
|
|
||||||
// same thing as above, it was copied to provide sorting (needed by table
|
|
||||||
// views in deck editors)
|
|
||||||
/** The items ordered. */
|
|
||||||
private final transient List<Entry<T, Integer>> itemsOrdered = new ArrayList<Map.Entry<T, Integer>>();
|
|
||||||
|
|
||||||
/** Whether list is in sync. */
|
|
||||||
protected transient boolean isListInSync = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* iterator.
|
* iterator.
|
||||||
*
|
*
|
||||||
@@ -183,29 +175,6 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
|
|||||||
return (this.items == null) || this.items.isEmpty();
|
return (this.items == null) || this.items.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* getOrderedList.
|
|
||||||
*
|
|
||||||
* @return List<Entry<T, Integer>>
|
|
||||||
*/
|
|
||||||
public final List<Entry<T, Integer>> getOrderedList() {
|
|
||||||
if (!this.isListInSync) {
|
|
||||||
this.rebuildOrderedList();
|
|
||||||
}
|
|
||||||
return this.itemsOrdered;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void rebuildOrderedList() {
|
|
||||||
this.itemsOrdered.clear();
|
|
||||||
if (this.items != null) {
|
|
||||||
for (final Entry<T, Integer> e : this.items.entrySet()) {
|
|
||||||
this.itemsOrdered.add(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.isListInSync = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* toFlatList.
|
* toFlatList.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
Name:Back from the Brink
|
Name:Back from the Brink
|
||||||
ManaCost:4 U U
|
ManaCost:4 U U
|
||||||
Types:Enchantment
|
Types:Enchantment
|
||||||
A:AB$ CopyPermanent | Cost$ ExileAndPay | Defined$ Exiled | SorcerySpeed$ True | SpellDescription$ Put a token onto the battlefield that's a copy of that card. Activate this ability only any time you could cast a sorcery.
|
A:AB$ CopyPermanent | Cost$ ExileFromGrave<1/Creature> Mana<X\Remembered> | Defined$ Exiled | SorcerySpeed$ True | SpellDescription$ Put a token onto the battlefield that's a copy of that card. Activate this ability only any time you could cast a sorcery.
|
||||||
SVar:NonStackingEffect:True
|
SVar:NonStackingEffect:True
|
||||||
SVar:Picture:http://www.wizards.com/global/images/magic/general/back_from_the_brink.jpg
|
SVar:Picture:http://www.wizards.com/global/images/magic/general/back_from_the_brink.jpg
|
||||||
Oracle:Exile a creature card from your graveyard and pay its mana cost: Put a token onto the battlefield that's a copy of that card. Activate this ability only any time you could cast a sorcery.
|
Oracle:Exile a creature card from your graveyard and pay its mana cost: Put a token onto the battlefield that's a copy of that card. Activate this ability only any time you could cast a sorcery.
|
||||||
@@ -81,7 +81,7 @@ public class DeckHtmlSerializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final TreeMap<String, Integer> map = new TreeMap<String, Integer>();
|
final TreeMap<String, Integer> map = new TreeMap<String, Integer>();
|
||||||
for (final Entry<PaperCard, Integer> entry : d.getMain().getOrderedList()) {
|
for (final Entry<PaperCard, Integer> entry : d.getMain()) {
|
||||||
map.put(entry.getKey().getName(), entry.getValue());
|
map.put(entry.getKey().getName(), entry.getValue());
|
||||||
// System.out.println(entry.getValue() + " " +
|
// System.out.println(entry.getValue() + " " +
|
||||||
// entry.getKey().getName());
|
// entry.getKey().getName());
|
||||||
|
|||||||
@@ -17,7 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
package forge.gui.toolbox.itemmanager;
|
package forge.gui.toolbox.itemmanager;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
@@ -63,8 +65,31 @@ public final class ItemManagerModel<T extends InventoryItem> {
|
|||||||
*
|
*
|
||||||
* @return List<Entry<T, Integer>>
|
* @return List<Entry<T, Integer>>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// same thing as above, it was copied to provide sorting (needed by table
|
||||||
|
// views in deck editors)
|
||||||
|
/** The items ordered. */
|
||||||
|
private final transient List<Entry<T, Integer>> itemsOrdered = new ArrayList<Map.Entry<T, Integer>>();
|
||||||
|
|
||||||
|
/** Whether list is in sync. */
|
||||||
|
protected transient boolean isListInSync = false;
|
||||||
|
|
||||||
public final List<Entry<T, Integer>> getOrderedList() {
|
public final List<Entry<T, Integer>> getOrderedList() {
|
||||||
return this.data.getOrderedList();
|
if (!this.isListInSync) {
|
||||||
|
this.rebuildOrderedList();
|
||||||
|
}
|
||||||
|
return this.itemsOrdered;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rebuildOrderedList() {
|
||||||
|
this.itemsOrdered.clear();
|
||||||
|
if (this.data != null) {
|
||||||
|
for (final Entry<T, Integer> e : this.data) {
|
||||||
|
this.itemsOrdered.add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.isListInSync = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,6 +122,7 @@ public final class ItemManagerModel<T extends InventoryItem> {
|
|||||||
final boolean wasThere = this.data.count(item0) > 0;
|
final boolean wasThere = this.data.count(item0) > 0;
|
||||||
if (wasThere) {
|
if (wasThere) {
|
||||||
this.data.remove(item0, qty);
|
this.data.remove(item0, qty);
|
||||||
|
isListInSync = false;
|
||||||
this.itemManager.getTable().getTableModel().fireTableDataChanged();
|
this.itemManager.getTable().getTableModel().fireTableDataChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,6 +134,7 @@ public final class ItemManagerModel<T extends InventoryItem> {
|
|||||||
*/
|
*/
|
||||||
public void addItem(final T item0, int qty) {
|
public void addItem(final T item0, int qty) {
|
||||||
this.data.add(item0, qty);
|
this.data.add(item0, qty);
|
||||||
|
isListInSync = false;
|
||||||
this.itemManager.getTable().getTableModel().fireTableDataChanged();
|
this.itemManager.getTable().getTableModel().fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +145,7 @@ public final class ItemManagerModel<T extends InventoryItem> {
|
|||||||
*/
|
*/
|
||||||
public void addItems(final Iterable<Entry<T, Integer>> items0) {
|
public void addItems(final Iterable<Entry<T, Integer>> items0) {
|
||||||
this.data.addAll(items0);
|
this.data.addAll(items0);
|
||||||
|
isListInSync = false;
|
||||||
this.itemManager.getTable().getTableModel().fireTableDataChanged();
|
this.itemManager.getTable().getTableModel().fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user