mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
* caching implementation CardPrinted.getMatchingForgeCard replaces toForgeCard without parameters.
This commit is contained in:
@@ -228,18 +228,7 @@ public class GameNew {
|
||||
int hand = p.getValue().getStartingHand();
|
||||
player.setMaxHandSize(hand);
|
||||
player.setStartingHandSize(hand);
|
||||
// what if I call it for AI player?
|
||||
PlayerZone bf = player.getZone(ZoneType.Battlefield);
|
||||
Iterable<Card> onTable = p.getValue().getCardsOnBattlefield();
|
||||
if (onTable != null) {
|
||||
for (final Card c : onTable) {
|
||||
c.setOwner(player);
|
||||
bf.add(c, false);
|
||||
c.setSickness(true);
|
||||
c.setStartsGameInPlay(true);
|
||||
c.refreshUniqueNumber();
|
||||
}
|
||||
}
|
||||
putCardsOnBattlefield(player, p.getValue().getCardsOnBattlefield(player));
|
||||
|
||||
PlayerZone com = player.getZone(ZoneType.Command);
|
||||
Iterable<Card> inCommand = p.getValue().getCardsInCommand(player);
|
||||
@@ -267,7 +256,7 @@ public class GameNew {
|
||||
|
||||
prepareSingleLibrary(player, toUse, removedAnteCards, rAICards, canRandomFoil);
|
||||
player.updateObservers();
|
||||
bf.updateObservers();
|
||||
player.getZone(ZoneType.Battlefield).updateObservers();
|
||||
player.getZone(ZoneType.Hand).updateObservers();
|
||||
player.getZone(ZoneType.Command).updateObservers();
|
||||
player.getZone(ZoneType.Battlefield).updateObservers();
|
||||
@@ -290,7 +279,22 @@ public class GameNew {
|
||||
|
||||
GameNew.actuateGame(game, false);
|
||||
}
|
||||
|
||||
private static void putCardsOnBattlefield(Player player, Iterable<Card> cards) {
|
||||
PlayerZone bf = player.getZone(ZoneType.Battlefield);
|
||||
if (cards != null) {
|
||||
for (final Card c : cards) {
|
||||
c.addController(player);
|
||||
bf.add(c, false);
|
||||
c.setSickness(true);
|
||||
c.setStartsGameInPlay(true);
|
||||
c.refreshUniqueNumber();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ultimate of Karn the Liberated
|
||||
public static void restartGame(final GameState game, final Player startingTurn, Map<Player, List<Card>> playerLibraries) {
|
||||
MatchController match = Singletons.getModel().getMatch();
|
||||
|
||||
@@ -320,19 +324,7 @@ public class GameNew {
|
||||
final Player player = p.getKey();
|
||||
player.setStartingLife(p.getValue().getStartingLife());
|
||||
player.setNumLandsPlayed(0);
|
||||
// what if I call it for AI player?
|
||||
PlayerZone bf = player.getZone(ZoneType.Battlefield);
|
||||
Iterable<Card> onTable = p.getValue().getCardsOnBattlefield();
|
||||
if (onTable != null) {
|
||||
for (final Card c : onTable) {
|
||||
c.addController(player);
|
||||
c.setOwner(player);
|
||||
bf.add(c, false);
|
||||
c.setSickness(true);
|
||||
c.setStartsGameInPlay(true);
|
||||
c.refreshUniqueNumber();
|
||||
}
|
||||
}
|
||||
putCardsOnBattlefield(player, p.getValue().getCardsOnBattlefield(player));
|
||||
|
||||
PlayerZone library = player.getZone(ZoneType.Library);
|
||||
List<Card> newLibrary = playerLibraries.get(player);
|
||||
@@ -341,7 +333,7 @@ public class GameNew {
|
||||
}
|
||||
|
||||
player.shuffle();
|
||||
bf.updateObservers();
|
||||
player.getZone(ZoneType.Battlefield).updateObservers();
|
||||
player.updateObservers();
|
||||
player.getZone(ZoneType.Hand).updateObservers();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package forge.game;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
import forge.Card;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.player.Player;
|
||||
@@ -14,7 +12,7 @@ public class PlayerStartConditions {
|
||||
|
||||
private int startingLife = 20;
|
||||
private int startingHand = 7;
|
||||
private Supplier<Iterable<Card>> cardsOnBattlefield = null;
|
||||
private Function<Player, Iterable<Card>> cardsOnBattlefield = null;
|
||||
private Function<Player, Iterable<Card>> cardsInCommand = null;
|
||||
private Function<Player, Iterable<Card>> schemes = null;
|
||||
|
||||
@@ -34,15 +32,15 @@ public class PlayerStartConditions {
|
||||
public final int getStartingLife() {
|
||||
return startingLife;
|
||||
}
|
||||
public final Iterable<Card> getCardsOnBattlefield() {
|
||||
return cardsOnBattlefield == null ? null : cardsOnBattlefield.get();
|
||||
public final Iterable<Card> getCardsOnBattlefield(Player p) {
|
||||
return cardsOnBattlefield == null ? null : cardsOnBattlefield.apply(p);
|
||||
}
|
||||
|
||||
public final void setStartingLife(int startingLife) {
|
||||
this.startingLife = startingLife;
|
||||
}
|
||||
|
||||
public final void setCardsOnBattlefield(Supplier<Iterable<Card>> cardsOnTable) {
|
||||
public final void setCardsOnBattlefield(Function<Player, Iterable<Card>> cardsOnTable) {
|
||||
this.cardsOnBattlefield = cardsOnTable;
|
||||
}
|
||||
|
||||
|
||||
@@ -301,7 +301,7 @@ public final class BoosterDraft implements IBoosterDraft {
|
||||
final List<Card> forAi = new ArrayList<Card>();
|
||||
final List<CardPrinted> booster = this.pack.get((iHumansBooster + i) % this.pack.size());
|
||||
for (final CardPrinted cr : booster) {
|
||||
forAi.add(cr.toForgeCard());
|
||||
forAi.add(cr.getMatchingForgeCard());
|
||||
}
|
||||
|
||||
final CardPrinted aiPick = this.draftAI.choose(booster, iPlayer++);
|
||||
|
||||
@@ -37,7 +37,6 @@ import javax.swing.JScrollPane;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import forge.Card;
|
||||
import forge.item.CardPrinted;
|
||||
|
||||
/**
|
||||
@@ -194,7 +193,6 @@ public class CardListViewer {
|
||||
}
|
||||
|
||||
private class SelListener implements ListSelectionListener {
|
||||
private Card[] cache = null;
|
||||
|
||||
@Override
|
||||
public void valueChanged(final ListSelectionEvent e) {
|
||||
@@ -202,20 +200,12 @@ public class CardListViewer {
|
||||
// (String) jList.getSelectedValue();
|
||||
if ((row >= 0) && (row < CardListViewer.this.list.size())) {
|
||||
final CardPrinted cp = CardListViewer.this.list.get(row);
|
||||
this.ensureCacheHas(row, cp);
|
||||
CardListViewer.this.detail.setCard(this.cache[row]);
|
||||
CardListViewer.this.detail.setCard(cp.getMatchingForgeCard());
|
||||
CardListViewer.this.picture.setCard(cp);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureCacheHas(final int row, final CardPrinted cp) {
|
||||
if (this.cache == null) {
|
||||
this.cache = new Card[CardListViewer.this.list.size()];
|
||||
}
|
||||
if (null == this.cache[row]) {
|
||||
this.cache[row] = cp.toForgeCard();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -159,8 +159,8 @@ public final class CardPicturePanel extends JPanel implements CardContainer {
|
||||
*/
|
||||
@Override
|
||||
public Card getCard() {
|
||||
if ((this.card == null) && (this.inventoryItem != null) && (this.inventoryItem instanceof CardPrinted)) {
|
||||
this.card = ((CardPrinted) this.inventoryItem).toForgeCard();
|
||||
if ((this.card == null) && this.inventoryItem instanceof CardPrinted) {
|
||||
this.card = ((CardPrinted) this.inventoryItem).getMatchingForgeCard();
|
||||
}
|
||||
return this.card;
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class DualListBox<T> extends FPanel {
|
||||
} else if (obj instanceof SpellAbility) {
|
||||
card = ((SpellAbility) obj).getSourceCard();
|
||||
} else if (obj instanceof CardPrinted) {
|
||||
card = ((CardPrinted) obj).toForgeCard();
|
||||
card = ((CardPrinted) obj).getMatchingForgeCard();
|
||||
}
|
||||
|
||||
GuiUtils.clearPanelSelections();
|
||||
|
||||
@@ -187,17 +187,14 @@ public final class EditorTableModel<T extends InventoryItem> extends AbstractTab
|
||||
final int row = table.getSelectedRow();
|
||||
if (row != -1) {
|
||||
final T cp = this.rowToCard(row).getKey();
|
||||
final Card card2;
|
||||
if (cp instanceof CardPrinted) {
|
||||
card2 = ((CardPrinted) cp).toForgeCard();
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.setCard(card2);
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.setCard(((CardPrinted) cp).getMatchingForgeCard());
|
||||
}
|
||||
else if (cp != null) {
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.setCard(cp);
|
||||
}
|
||||
else {
|
||||
card2 = null;
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.setCard(card2);
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.setCard((Card)null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ public enum VProbabilities implements IVDoc<CProbabilities> {
|
||||
if (name2.length() > name1.length()) { continue; }
|
||||
|
||||
if (name2.equals(name1.substring(0, name2.length()))) {
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.setCard(c.toForgeCard());
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.setCard(c.getMatchingForgeCard());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ import javax.swing.SwingWorker;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import forge.Card;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardEdition;
|
||||
@@ -22,6 +21,7 @@ import forge.game.GameType;
|
||||
import forge.game.MatchStartHelper;
|
||||
import forge.game.PlayerStartConditions;
|
||||
import forge.game.player.LobbyPlayer;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.PlayerType;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.gui.SOverlayUtils;
|
||||
@@ -387,10 +387,10 @@ public class SSubmenuQuestUtil {
|
||||
humanStart.setStartingLife(qData.getAssets().getLife(qData.getMode()) + extraLifeHuman);
|
||||
aiStart.setStartingLife(lifeAI);
|
||||
|
||||
humanStart.setCardsOnBattlefield(new Supplier<Iterable<Card>>() {
|
||||
@Override public Iterable<Card> get() { return QuestUtil.getHumanStartingCards(qData, event); } });
|
||||
aiStart.setCardsOnBattlefield(new Supplier<Iterable<Card>>() {
|
||||
@Override public Iterable<Card> get() { return QuestUtil.getComputerStartingCards(event); } });
|
||||
humanStart.setCardsOnBattlefield(new Function<Player, Iterable<Card>>() {
|
||||
@Override public Iterable<Card> apply(Player p) { return QuestUtil.getHumanStartingCards(qData, event, p); } });
|
||||
aiStart.setCardsOnBattlefield(new Function<Player, Iterable<Card>>() {
|
||||
@Override public Iterable<Card> apply(Player p) { return QuestUtil.getComputerStartingCards(event, p); } });
|
||||
} // End isFantasy
|
||||
|
||||
MatchStartHelper msh = new MatchStartHelper();
|
||||
|
||||
@@ -131,9 +131,8 @@ public enum VSubmenuVanguard implements IVSubmenu<CSubmenuVanguard> {
|
||||
int index = avatarLists.indexOf(arg0.getSource());
|
||||
Object obj = avatarLists.get(index).getSelectedValue();
|
||||
|
||||
if (!(obj instanceof String)) {
|
||||
|
||||
cdpAvatarDetails.get(index).setCard(((CardPrinted) obj).toForgeCard());
|
||||
if (obj instanceof CardPrinted) {
|
||||
cdpAvatarDetails.get(index).setCard(((CardPrinted) obj).getMatchingForgeCard());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.Card;
|
||||
import forge.gui.CardDetailPanel;
|
||||
import forge.gui.CardPicturePanel;
|
||||
import forge.gui.toolbox.FList;
|
||||
@@ -98,28 +97,16 @@ public class QuestWinLoseCardViewer extends FPanel {
|
||||
}
|
||||
|
||||
private class SelListener implements ListSelectionListener {
|
||||
private Card[] cache = null;
|
||||
|
||||
@Override
|
||||
public void valueChanged(final ListSelectionEvent e) {
|
||||
final int row = QuestWinLoseCardViewer.this.jList.getSelectedIndex();
|
||||
// (String) jList.getSelectedValue();
|
||||
if ((row >= 0) && (row < QuestWinLoseCardViewer.this.list.size())) {
|
||||
final CardPrinted cp = QuestWinLoseCardViewer.this.list.get(row);
|
||||
this.ensureCacheHas(row, cp);
|
||||
QuestWinLoseCardViewer.this.detail.setCard(this.cache[row]);
|
||||
QuestWinLoseCardViewer.this.detail.setCard(cp.getMatchingForgeCard());
|
||||
QuestWinLoseCardViewer.this.picture.setCard(cp);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureCacheHas(final int row, final CardPrinted cp) {
|
||||
if (this.cache == null) {
|
||||
this.cache = new Card[QuestWinLoseCardViewer.this.list.size()];
|
||||
}
|
||||
if (null == this.cache[row]) {
|
||||
this.cache[row] = cp.toForgeCard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import javax.swing.JScrollPane;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import forge.Card;
|
||||
import forge.gui.CardDetailPanel;
|
||||
import forge.gui.CardPicturePanel;
|
||||
import forge.item.CardPrinted;
|
||||
@@ -87,28 +86,17 @@ public class CardViewer extends JPanel {
|
||||
}
|
||||
|
||||
private class SelListener implements ListSelectionListener {
|
||||
private Card[] cache = null;
|
||||
|
||||
@Override
|
||||
public void valueChanged(final ListSelectionEvent e) {
|
||||
final int row = CardViewer.this.jList.getSelectedIndex();
|
||||
// (String) jList.getSelectedValue();
|
||||
if ((row >= 0) && (row < CardViewer.this.list.size())) {
|
||||
final CardPrinted cp = CardViewer.this.list.get(row);
|
||||
this.ensureCacheHas(row, cp);
|
||||
CardViewer.this.detail.setCard(this.cache[row]);
|
||||
CardViewer.this.detail.setCard(cp.getMatchingForgeCard());
|
||||
CardViewer.this.picture.setCard(cp);
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureCacheHas(final int row, final CardPrinted cp) {
|
||||
if (this.cache == null) {
|
||||
this.cache = new Card[CardViewer.this.list.size()];
|
||||
}
|
||||
if (null == this.cache[row]) {
|
||||
this.cache[row] = cp.toForgeCard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
package forge.item;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
@@ -295,8 +297,14 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
||||
*
|
||||
* @return the card
|
||||
*/
|
||||
public Card toForgeCard() {
|
||||
return toForgeCard(null);
|
||||
private static final Map<CardPrinted, Card> cp2card = new HashMap<CardPrinted, Card>();
|
||||
public Card getMatchingForgeCard() {
|
||||
Card res = cp2card.get(this);
|
||||
if (null == res) {
|
||||
res = toForgeCard(null);
|
||||
cp2card.put(this, res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,7 @@ package forge.quest;
|
||||
import forge.Card;
|
||||
|
||||
import forge.card.cardfactory.CardFactory;
|
||||
import forge.game.player.Player;
|
||||
import forge.item.CardDb;
|
||||
import forge.quest.bazaar.QuestPetController;
|
||||
|
||||
@@ -61,11 +62,11 @@ public class QuestUtil {
|
||||
* a {@link forge.quest.QuestEvent} object.
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public static List<Card> getComputerStartingCards(final QuestEvent qe) {
|
||||
public static List<Card> getComputerStartingCards(final QuestEvent qe, Player ai) {
|
||||
final List<Card> list = new ArrayList<Card>();
|
||||
|
||||
for (final String s : qe.getAiExtraCards()) {
|
||||
list.add(QuestUtil.readExtraCard(s));
|
||||
list.add(QuestUtil.readExtraCard(s, ai));
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -116,10 +117,10 @@ public class QuestUtil {
|
||||
* a {@link forge.quest.QuestEvent} object.
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public static List<Card> getHumanStartingCards(final QuestController qc, final QuestEvent qe) {
|
||||
public static List<Card> getHumanStartingCards(final QuestController qc, final QuestEvent qe, final Player human) {
|
||||
final List<Card> list = QuestUtil.getHumanStartingCards(qc);
|
||||
for (final String s : qe.getHumanExtraCards()) {
|
||||
list.add(QuestUtil.readExtraCard(s));
|
||||
list.add(QuestUtil.readExtraCard(s, human));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -168,17 +169,16 @@ public class QuestUtil {
|
||||
* the owner
|
||||
* @return the card
|
||||
*/
|
||||
public static Card readExtraCard(final String name) {
|
||||
public static Card readExtraCard(final String name, Player owner) {
|
||||
// Token card creation
|
||||
Card tempcard;
|
||||
if (name.startsWith("TOKEN")) {
|
||||
tempcard = QuestUtil.createToken(name);
|
||||
tempcard.setOwner(owner);
|
||||
return tempcard;
|
||||
}
|
||||
// Standard card creation
|
||||
else {
|
||||
tempcard = CardDb.instance().getCard(name, true).toForgeCard();
|
||||
}
|
||||
return tempcard;
|
||||
return CardDb.instance().getCard(name, true).toForgeCard(owner);
|
||||
}
|
||||
|
||||
} // QuestUtil
|
||||
|
||||
Reference in New Issue
Block a user