forked from External/mage
Refactor: removed server side objects from a client side game's data (#10788)
* Clean original values transmitted with CardView.originalObject * Move RateCard to mage.Common, support cardView as argument. * Clean PermanentView constructor for TestCardRenderDialog
This commit is contained in:
parent
ba411e0054
commit
5062c84098
17 changed files with 285 additions and 149 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package mage.view;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import mage.MageInt;
|
||||
import mage.MageObject;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Abilities;
|
||||
|
|
@ -74,8 +75,8 @@ public class CardView extends SimpleCardView {
|
|||
protected ObjectColor frameColor;
|
||||
protected FrameStyle frameStyle;
|
||||
// can combine multiple costs for MockCard from deck editor or db (left/right, card/adventure)
|
||||
protected String manaCostLeftStr;
|
||||
protected String manaCostRightStr;
|
||||
protected List<String> manaCostLeftStr;
|
||||
protected List<String> manaCostRightStr;
|
||||
protected int manaValue;
|
||||
protected Rarity rarity;
|
||||
|
||||
|
|
@ -130,7 +131,13 @@ public class CardView extends SimpleCardView {
|
|||
protected boolean inViewerOnly; // GUI render: show object as a card instead permanent (without PT, etc)
|
||||
protected List<CardIcon> cardIcons = new ArrayList<>(); // additional icons to render
|
||||
|
||||
protected MageObject originalObject = null; // GUI related: additional info about current object (example: real PT)
|
||||
// GUI related: additional info about current object (example: real PT)
|
||||
protected MageInt originalPower = null;
|
||||
protected MageInt originalToughness = null;
|
||||
protected FilterMana originalColorIdentity = null;
|
||||
protected UUID originalId = null;
|
||||
protected boolean originalIsCopy = false;
|
||||
protected boolean originalIsCard = false;
|
||||
|
||||
/**
|
||||
* Non game usage like deck editor
|
||||
|
|
@ -237,7 +244,12 @@ public class CardView extends SimpleCardView {
|
|||
this.canAttack = cardView.canAttack;
|
||||
this.canBlock = cardView.canBlock;
|
||||
this.inViewerOnly = cardView.inViewerOnly;
|
||||
this.originalObject = cardView.originalObject == null ? null : cardView.originalObject.copy();
|
||||
this.originalPower = cardView.originalPower;
|
||||
this.originalToughness = cardView.originalToughness;
|
||||
this.originalColorIdentity = cardView.originalColorIdentity;
|
||||
this.originalId = cardView.originalId;
|
||||
this.originalIsCard = cardView.originalIsCard;
|
||||
this.originalIsCopy = cardView.originalIsCopy;
|
||||
if (cardView.cardIcons != null) {
|
||||
cardView.cardIcons.forEach(icon -> this.cardIcons.add(icon.copy()));
|
||||
}
|
||||
|
|
@ -287,7 +299,7 @@ public class CardView extends SimpleCardView {
|
|||
*/
|
||||
public CardView(Card card, Game game, boolean controlled, boolean showFaceDownCard, boolean storeZone) {
|
||||
super(card.getId(), card.getExpansionSetCode(), card.getCardNumber(), card.getUsesVariousArt(), game != null);
|
||||
this.originalObject = card;
|
||||
this.setOriginalValues(card);
|
||||
this.imageNumber = card.getImageNumber();
|
||||
|
||||
// no information available for face down cards as long it's not a controlled face down morph card
|
||||
|
|
@ -375,29 +387,29 @@ public class CardView extends SimpleCardView {
|
|||
rightSplitTypeLine = getCardTypeLine(game, splitCard.getRightHalfCard());
|
||||
|
||||
fullCardName = card.getName(); // split card contains full name as normal
|
||||
this.manaCostLeftStr = String.join("", splitCard.getLeftHalfCard().getManaCostSymbols());
|
||||
this.manaCostRightStr = String.join("", splitCard.getRightHalfCard().getManaCostSymbols());
|
||||
this.manaCostLeftStr = splitCard.getLeftHalfCard().getManaCostSymbols();
|
||||
this.manaCostRightStr = splitCard.getRightHalfCard().getManaCostSymbols();
|
||||
} else if (card instanceof ModalDoubleFacedCard) {
|
||||
this.isModalDoubleFacedCard = true;
|
||||
ModalDoubleFacedCard mainCard = ((ModalDoubleFacedCard) card);
|
||||
fullCardName = mainCard.getLeftHalfCard().getName() + MockCard.MODAL_DOUBLE_FACES_NAME_SEPARATOR + mainCard.getRightHalfCard().getName();
|
||||
this.manaCostLeftStr = String.join("", mainCard.getLeftHalfCard().getManaCostSymbols());
|
||||
this.manaCostRightStr = String.join("", mainCard.getRightHalfCard().getManaCostSymbols());
|
||||
this.manaCostLeftStr = mainCard.getLeftHalfCard().getManaCostSymbols();
|
||||
this.manaCostRightStr = mainCard.getRightHalfCard().getManaCostSymbols();
|
||||
} else if (card instanceof AdventureCard) {
|
||||
AdventureCard adventureCard = ((AdventureCard) card);
|
||||
AdventureCardSpell adventureCardSpell = adventureCard.getSpellCard();
|
||||
fullCardName = adventureCard.getName() + MockCard.ADVENTURE_NAME_SEPARATOR + adventureCardSpell.getName();
|
||||
this.manaCostLeftStr = String.join("", adventureCardSpell.getManaCostSymbols());
|
||||
this.manaCostRightStr = String.join("", adventureCard.getManaCostSymbols());
|
||||
this.manaCostLeftStr = adventureCardSpell.getManaCostSymbols();
|
||||
this.manaCostRightStr = adventureCard.getManaCostSymbols();
|
||||
} else if (card instanceof MockCard) {
|
||||
// deck editor cards
|
||||
fullCardName = ((MockCard) card).getFullName(true);
|
||||
this.manaCostLeftStr = String.join("", ((MockCard) card).getManaCostStr(CardInfo.ManaCostSide.LEFT));
|
||||
this.manaCostRightStr = String.join("", ((MockCard) card).getManaCostStr(CardInfo.ManaCostSide.RIGHT));
|
||||
this.manaCostLeftStr = ((MockCard) card).getManaCostStr(CardInfo.ManaCostSide.LEFT);
|
||||
this.manaCostRightStr = ((MockCard) card).getManaCostStr(CardInfo.ManaCostSide.RIGHT);
|
||||
} else {
|
||||
fullCardName = card.getName();
|
||||
this.manaCostLeftStr = String.join("", card.getManaCostSymbols());
|
||||
this.manaCostRightStr = "";
|
||||
this.manaCostLeftStr = card.getManaCostSymbols();
|
||||
this.manaCostRightStr = new ArrayList<>();
|
||||
}
|
||||
|
||||
this.name = card.getName();
|
||||
|
|
@ -616,7 +628,7 @@ public class CardView extends SimpleCardView {
|
|||
|
||||
public CardView(MageObject object, Game game) {
|
||||
super(object.getId(), object.getExpansionSetCode(), object.getCardNumber(), false, true);
|
||||
this.originalObject = object;
|
||||
this.setOriginalValues(object);
|
||||
|
||||
this.imageNumber = object.getImageNumber();
|
||||
this.name = object.getName();
|
||||
|
|
@ -638,8 +650,8 @@ public class CardView extends SimpleCardView {
|
|||
this.subTypes = object.getSubtype(game).copy();
|
||||
this.superTypes = new ArrayList<>(object.getSuperType(game));
|
||||
this.color = object.getColor(game).copy();
|
||||
this.manaCostLeftStr = String.join("", object.getManaCostSymbols());
|
||||
this.manaCostRightStr = "";
|
||||
this.manaCostLeftStr = object.getManaCostSymbols();
|
||||
this.manaCostRightStr = new ArrayList<>();
|
||||
this.manaValue = object.getManaCost().manaValue();
|
||||
if (object instanceof PermanentToken) {
|
||||
this.mageObjectType = MageObjectType.TOKEN;
|
||||
|
|
@ -694,7 +706,6 @@ public class CardView extends SimpleCardView {
|
|||
|
||||
public CardView(EmblemView emblem) {
|
||||
this(true);
|
||||
this.originalObject = null;
|
||||
this.gameObject = true;
|
||||
this.id = emblem.getId();
|
||||
this.mageObjectType = MageObjectType.EMBLEM;
|
||||
|
|
@ -716,7 +727,6 @@ public class CardView extends SimpleCardView {
|
|||
|
||||
public CardView(DungeonView dungeon) {
|
||||
this(true);
|
||||
this.originalObject = null;
|
||||
this.gameObject = true;
|
||||
this.id = dungeon.getId();
|
||||
this.mageObjectType = MageObjectType.DUNGEON;
|
||||
|
|
@ -738,7 +748,6 @@ public class CardView extends SimpleCardView {
|
|||
|
||||
public CardView(PlaneView plane) {
|
||||
this(true);
|
||||
this.originalObject = null;
|
||||
this.gameObject = true;
|
||||
this.id = plane.getId();
|
||||
this.mageObjectType = MageObjectType.PLANE;
|
||||
|
|
@ -761,7 +770,6 @@ public class CardView extends SimpleCardView {
|
|||
|
||||
public CardView(Designation designation, StackAbility stackAbility) {
|
||||
this(true);
|
||||
this.originalObject = null;
|
||||
this.gameObject = true;
|
||||
this.id = designation.getId();
|
||||
this.mageObjectType = MageObjectType.NULL;
|
||||
|
|
@ -788,7 +796,6 @@ public class CardView extends SimpleCardView {
|
|||
}
|
||||
|
||||
private void fillEmpty(Card card, boolean controlled) {
|
||||
this.originalObject = null;
|
||||
this.name = "Face Down";
|
||||
this.displayName = name;
|
||||
this.displayFullName = name;
|
||||
|
|
@ -805,8 +812,8 @@ public class CardView extends SimpleCardView {
|
|||
this.color = new ObjectColor();
|
||||
this.frameColor = new ObjectColor();
|
||||
this.frameStyle = FrameStyle.M15_NORMAL;
|
||||
this.manaCostLeftStr = "";
|
||||
this.manaCostRightStr = "";
|
||||
this.manaCostLeftStr = new ArrayList<>();
|
||||
this.manaCostRightStr = new ArrayList<>();
|
||||
this.manaValue = 0;
|
||||
|
||||
// the controller can see more information (e.g. enlarged image) than other players for face down cards (e.g. Morph played face down)
|
||||
|
|
@ -857,8 +864,8 @@ public class CardView extends SimpleCardView {
|
|||
this.color = token.getColor(game).copy();
|
||||
this.frameColor = token.getFrameColor(game).copy();
|
||||
this.frameStyle = token.getFrameStyle();
|
||||
this.manaCostLeftStr = String.join("", token.getManaCostSymbols());
|
||||
this.manaCostRightStr = "";
|
||||
this.manaCostLeftStr = token.getManaCostSymbols();
|
||||
this.manaCostRightStr = new ArrayList<>();
|
||||
this.rarity = Rarity.SPECIAL;
|
||||
|
||||
// source object is a token, so no card number
|
||||
|
|
@ -894,6 +901,26 @@ public class CardView extends SimpleCardView {
|
|||
this.targets.addAll(newTargets);
|
||||
}
|
||||
|
||||
private void setOriginalValues(MageObject object) {
|
||||
if (object == null) {
|
||||
return;
|
||||
}
|
||||
// Only valid objects to transfer original values are Card and Token
|
||||
if (object instanceof Card || object instanceof Token) {
|
||||
this.originalPower = object.getPower();
|
||||
this.originalToughness = object.getToughness();
|
||||
this.originalIsCopy = object.isCopy();
|
||||
this.originalId = object.getId();
|
||||
|
||||
if (object instanceof Card) {
|
||||
this.originalColorIdentity = ((Card) object).getColorIdentity();
|
||||
this.originalIsCard = true;
|
||||
} else if (object instanceof Token) {
|
||||
this.originalColorIdentity = ManaUtil.getColorIdentity((Token) object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
@ -979,7 +1006,22 @@ public class CardView extends SimpleCardView {
|
|||
}
|
||||
|
||||
public String getManaCostStr() {
|
||||
return CardUtil.concatManaSymbols(CardInfo.SPLIT_MANA_SEPARATOR_FULL, this.manaCostLeftStr, this.manaCostRightStr);
|
||||
return CardUtil.concatManaSymbols(
|
||||
CardInfo.SPLIT_MANA_SEPARATOR_FULL,
|
||||
String.join("", this.manaCostLeftStr),
|
||||
String.join("", this.manaCostRightStr)
|
||||
);
|
||||
}
|
||||
|
||||
public List<String> getManaCostSymbols() {
|
||||
List<String> symbols = new ArrayList<>();
|
||||
for (String symbol : this.manaCostLeftStr) {
|
||||
symbols.add(symbol);
|
||||
}
|
||||
for (String symbol : this.manaCostRightStr) {
|
||||
symbols.add(symbol);
|
||||
}
|
||||
return symbols;
|
||||
}
|
||||
|
||||
public int getManaValue() {
|
||||
|
|
@ -991,14 +1033,8 @@ public class CardView extends SimpleCardView {
|
|||
}
|
||||
|
||||
public String getColorIdentityStr() {
|
||||
FilterMana colorInfo;
|
||||
if (getOriginalCard() != null) {
|
||||
// card
|
||||
colorInfo = getOriginalCard().getColorIdentity();
|
||||
} else if (getOriginalToken() != null) {
|
||||
// token
|
||||
colorInfo = ManaUtil.getColorIdentity(getOriginalToken());
|
||||
} else {
|
||||
FilterMana colorInfo = this.originalColorIdentity;
|
||||
if (colorInfo != null) {
|
||||
colorInfo = new FilterMana();
|
||||
}
|
||||
|
||||
|
|
@ -1285,20 +1321,24 @@ public class CardView extends SimpleCardView {
|
|||
return inViewerOnly;
|
||||
}
|
||||
|
||||
public Card getOriginalCard() {
|
||||
if (this.originalObject instanceof Card) {
|
||||
return (Card) this.originalObject;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
public MageInt getOriginalPower() {
|
||||
return this.originalPower;
|
||||
}
|
||||
|
||||
public Token getOriginalToken() {
|
||||
if (this.originalObject instanceof Token) {
|
||||
return (Token) this.originalObject;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
public MageInt getOriginalToughness() {
|
||||
return this.originalToughness;
|
||||
}
|
||||
|
||||
public UUID getOriginalId() {
|
||||
return this.originalId;
|
||||
}
|
||||
|
||||
public boolean isOriginalACopy() {
|
||||
return this.originalIsCopy;
|
||||
}
|
||||
|
||||
public boolean isOriginalACard() {
|
||||
return this.originalIsCard;
|
||||
}
|
||||
|
||||
public List<CardIcon> getCardIcons() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue