added SimpleCardView - will reduce the amount of data passed between client and server

This commit is contained in:
BetaSteward 2011-08-22 13:54:55 -04:00
parent 91124ad813
commit aecdbe0778
20 changed files with 273 additions and 74 deletions

View file

@ -49,10 +49,9 @@ import mage.target.Targets;
/**
* @author BetaSteward_at_googlemail.com
*/
public class CardView implements Serializable {
public class CardView extends SimpleCardView {
private static final long serialVersionUID = 1L;
protected UUID id;
protected UUID parentId;
protected String name;
protected List<String> rules;
@ -66,17 +65,18 @@ public class CardView implements Serializable {
protected List<String> manaCost;
protected int convertedManaCost;
protected Rarity rarity;
protected String expansionSetCode;
protected int cardNumber;
protected boolean isAbility;
protected CardView ability;
protected boolean faceDown;
public List<UUID> targets;
public CardView(Card card, UUID cardId) {
this(card);
this.id = cardId;
}
public CardView(Card card) {
this.id = card.getId();
this.faceDown = card.isFaceDown();
super(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown());
// no information available for face down cards
if (this.faceDown) {
@ -106,8 +106,6 @@ public class CardView implements Serializable {
} else {
this.rarity = card.getRarity();
}
this.expansionSetCode = card.getExpansionSetCode();
this.cardNumber = card.getCardNumber();
if (card instanceof Spell) {
Spell<?> spell = (Spell<?>) card;
@ -118,7 +116,7 @@ public class CardView implements Serializable {
}
public CardView(MageObject card) {
this.id = card.getId();
super(card.getId(), "", 0, false);
this.name = card.getName();
if (card instanceof Permanent) {
@ -144,9 +142,10 @@ public class CardView implements Serializable {
}
protected CardView() {
super(null, "", 0, false);
}
private void fillEmpty() {
private void fillEmpty() {
this.name = "Face Down";
this.rules = new ArrayList<String>();
this.power = "";
@ -164,6 +163,7 @@ public class CardView implements Serializable {
}
CardView(Token token) {
super(token.getId(), "", 0, false);
this.id = token.getId();
this.name = token.getName();
this.rules = token.getAbilities().getRules(this.name);

View file

@ -36,7 +36,6 @@ import mage.abilities.Ability;
import mage.cards.Card;
import mage.game.Game;
import mage.game.GameState;
import mage.game.permanent.Permanent;
/**
*

View file

@ -27,13 +27,9 @@
*/
package mage.view;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.decks.Deck;
import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* @author nantuko
@ -41,24 +37,24 @@ import java.util.Set;
public class DeckView implements Serializable {
private String name;
private CardsView cards;
private CardsView sideboard;
private SimpleCardsView cards;
private SimpleCardsView sideboard;
public DeckView(Deck deck) {
name = deck.getName();
cards = new CardsView(deck.getCards());
sideboard = new CardsView(deck.getSideboard());
cards = new SimpleCardsView(deck.getCards());
sideboard = new SimpleCardsView(deck.getSideboard());
}
public String getName() {
return name;
}
public CardsView getCards() {
public SimpleCardsView getCards() {
return cards;
}
public CardsView getSideboard() {
public SimpleCardsView getSideboard() {
return sideboard;
}
}

View file

@ -38,23 +38,23 @@ import mage.game.draft.DraftPlayer;
public class DraftPickView implements Serializable {
private static final long serialVersionUID = 1L;
protected CardsView booster;
protected CardsView picks;
protected SimpleCardsView booster;
protected SimpleCardsView picks;
protected boolean picking;
protected int timeout;
public DraftPickView(DraftPlayer player, int timeout) {
this.booster = new CardsView(player.getBooster());
this.picks = new CardsView(player.getDeck().getSideboard());
this.booster = new SimpleCardsView(player.getBooster());
this.picks = new SimpleCardsView(player.getDeck().getSideboard());
this.picking = player.isPicking();
this.timeout = timeout;
}
public CardsView getBooster() {
public SimpleCardsView getBooster() {
return booster;
}
public CardsView getPicks() {
public SimpleCardsView getPicks() {
return picks;
}

View file

@ -37,7 +37,7 @@ import mage.game.Game;
*
* @author BetaSteward_at_googlemail.com
*/
public class ExileView extends CardsView {
public class ExileView extends SimpleCardsView {
private static final long serialVersionUID = 1L;
private String name;
@ -47,7 +47,7 @@ public class ExileView extends CardsView {
this.name = exileZone.getName();
this.id = exileZone.getId();
for (Card card: exileZone.getCards(game)) {
this.put(card.getId(), new CardView(card));
this.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown()));
}
}

View file

@ -32,13 +32,11 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.MageObject;
import mage.Constants.PhaseStep;
import mage.Constants.TurnPhase;
import mage.cards.Card;
import mage.cards.Cards;
import mage.game.ExileZone;
import mage.game.Game;
import mage.game.GameState;
@ -56,8 +54,8 @@ public class GameView implements Serializable {
private static final long serialVersionUID = 1L;
private List<PlayerView> players = new ArrayList<PlayerView>();
private CardsView hand;
private Map<String, CardsView> opponentHands;
private SimpleCardsView hand;
private Map<String, SimpleCardsView> opponentHands;
private CardsView stack = new CardsView();
private List<ExileView> exiles = new ArrayList<ExileView>();
private List<RevealedView> revealed = new ArrayList<RevealedView>();
@ -118,19 +116,19 @@ public class GameView implements Serializable {
return players;
}
public CardsView getHand() {
public SimpleCardsView getHand() {
return hand;
}
public void setHand(CardsView hand) {
public void setHand(SimpleCardsView hand) {
this.hand = hand;
}
public Map<String, CardsView> getOpponentHands() {
public Map<String, SimpleCardsView> getOpponentHands() {
return opponentHands;
}
public void setOpponentHands(Map<String, CardsView> opponentHands) {
public void setOpponentHands(Map<String, SimpleCardsView> opponentHands) {
this.opponentHands = opponentHands;
}

View file

@ -41,12 +41,12 @@ import java.io.Serializable;
public class LookedAtView implements Serializable {
private String name;
private CardsView cards = new CardsView();
private SimpleCardsView cards = new SimpleCardsView();
public LookedAtView(String name, Cards cards, Game game) {
this.name = name;
for (Card card: cards.getCards(game)) {
this.cards.put(card.getId(), new CardView(card));
this.cards.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown()));
}
}
@ -54,7 +54,7 @@ public class LookedAtView implements Serializable {
return name;
}
public CardsView getCards() {
public SimpleCardsView getCards() {
return cards;
}
}

View file

@ -55,7 +55,7 @@ public class PlayerView implements Serializable {
private boolean isActive;
private boolean hasLeft;
private ManaPoolView manaPool;
private CardsView graveyard = new CardsView();
private SimpleCardsView graveyard = new SimpleCardsView();
private Map<UUID, PermanentView> battlefield = new HashMap<UUID, PermanentView>();
public PlayerView(Player player, GameState state, Game game) {
@ -69,7 +69,7 @@ public class PlayerView implements Serializable {
this.isActive = (player.getId().equals(state.getActivePlayerId()));
this.hasLeft = player.hasLeft();
for (Card card: player.getGraveyard().getCards(game)) {
graveyard.put(card.getId(), new CardView(card));
graveyard.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown()));
}
for (Permanent permanent: state.getBattlefield().getAllPermanents()) {
if (showInBattlefield(permanent, state)) {
@ -113,7 +113,7 @@ public class PlayerView implements Serializable {
return this.manaPool;
}
public CardsView getGraveyard() {
public SimpleCardsView getGraveyard() {
return this.graveyard;
}

View file

@ -40,12 +40,12 @@ import mage.game.Game;
public class RevealedView implements Serializable {
private String name;
private CardsView cards = new CardsView();
private SimpleCardsView cards = new SimpleCardsView();
public RevealedView(String name, Cards cards, Game game) {
this.name = name;
for (Card card: cards.getCards(game)) {
this.cards.put(card.getId(), new CardView(card));
this.cards.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown()));
}
}
@ -53,7 +53,7 @@ public class RevealedView implements Serializable {
return name;
}
public CardsView getCards() {
public SimpleCardsView getCards() {
return cards;
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.view;
import java.io.Serializable;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class SimpleCardView implements Serializable {
protected UUID id;
protected String expansionSetCode;
protected int cardNumber;
protected boolean faceDown;
public SimpleCardView(UUID id, String expansionSetCode, int cardNumber, boolean faceDown) {
this.id = id;
this.expansionSetCode = expansionSetCode;
this.cardNumber = cardNumber;
this.faceDown = faceDown;
}
public UUID getId() {
return id;
}
public String getExpansionSetCode() {
return expansionSetCode;
}
public int getCardNumber() {
return cardNumber;
}
public boolean isFaceDown() {
return faceDown;
}
}

View file

@ -0,0 +1,50 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.view;
import java.util.Collection;
import java.util.HashMap;
import java.util.UUID;
import mage.cards.Card;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class SimpleCardsView extends HashMap<UUID, SimpleCardView> {
public SimpleCardsView() {}
public SimpleCardsView(Collection<Card> cards) {
for (Card card: cards) {
this.put(card.getId(), new SimpleCardView(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.isFaceDown()));
}
}
}