mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
Refactor: fixed getRules usage, clean SplitCard code
This commit is contained in:
parent
8f748b0f2c
commit
914cfc1d3a
9 changed files with 70 additions and 51 deletions
|
|
@ -118,13 +118,7 @@ public abstract class CardRenderer {
|
||||||
public CardRenderer(CardView card) {
|
public CardRenderer(CardView card) {
|
||||||
// Set base parameters
|
// Set base parameters
|
||||||
this.cardView = card;
|
this.cardView = card;
|
||||||
|
parseRules(card.getRules(), textboxKeywords, textboxRules);
|
||||||
if (card.getArtRect() == ArtRect.SPLIT_FUSED) {
|
|
||||||
parseRules(card.getLeftSplitRules(), textboxKeywords, textboxRules);
|
|
||||||
parseRules(card.getRightSplitRules(), textboxKeywords, textboxRules);
|
|
||||||
} else {
|
|
||||||
parseRules(card.getRules(), textboxKeywords, textboxRules);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseRules(List<String> stringRules, List<TextboxRule> keywords, List<TextboxRule> rules) {
|
protected void parseRules(List<String> stringRules, List<TextboxRule> keywords, List<TextboxRule> rules) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package org.mage.card.arcane;
|
||||||
|
|
||||||
import mage.ObjectColor;
|
import mage.ObjectColor;
|
||||||
import mage.cards.ArtRect;
|
import mage.cards.ArtRect;
|
||||||
|
import mage.cards.SplitCard;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.view.CardView;
|
import mage.view.CardView;
|
||||||
|
|
||||||
|
|
@ -17,6 +18,9 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class ModernSplitCardRenderer extends ModernCardRenderer {
|
public class ModernSplitCardRenderer extends ModernCardRenderer {
|
||||||
|
|
||||||
|
static String RULES_MARK_FUSE = "Fuse";
|
||||||
|
static String RULES_MARK_AFTERMATH = "Aftermath";
|
||||||
|
|
||||||
private static class HalfCardProps {
|
private static class HalfCardProps {
|
||||||
|
|
||||||
int x, y, w, h, cw, ch;
|
int x, y, w, h, cw, ch;
|
||||||
|
|
@ -61,8 +65,8 @@ public class ModernSplitCardRenderer extends ModernCardRenderer {
|
||||||
rightHalf.name = cardView.getRightSplitName();
|
rightHalf.name = cardView.getRightSplitName();
|
||||||
leftHalf.name = cardView.getLeftSplitName();
|
leftHalf.name = cardView.getLeftSplitName();
|
||||||
|
|
||||||
isFuse = view.getRules().stream().anyMatch(rule -> rule.contains("Fuse"));
|
isFuse = view.getRules().stream().anyMatch(rule -> rule.contains(RULES_MARK_FUSE));
|
||||||
isAftermath = view.getRightSplitRules().stream().anyMatch(rule -> rule.contains("Aftermath"));
|
isAftermath = view.getRightSplitRules().stream().anyMatch(rule -> rule.contains(RULES_MARK_AFTERMATH));
|
||||||
|
|
||||||
// It's easier for rendering to swap the card halves here because for aftermath cards
|
// It's easier for rendering to swap the card halves here because for aftermath cards
|
||||||
// they "rotate" in opposite directions making consquence and normal split cards
|
// they "rotate" in opposite directions making consquence and normal split cards
|
||||||
|
|
@ -298,7 +302,7 @@ public class ModernSplitCardRenderer extends ModernCardRenderer {
|
||||||
totalFuseBoxWidth, boxHeight,
|
totalFuseBoxWidth, boxHeight,
|
||||||
contentInset,
|
contentInset,
|
||||||
borderPaint, boxColor);
|
borderPaint, boxColor);
|
||||||
drawNameLine(g2, attribs, "Fuse (You may cast both halves from your hand)", "",
|
drawNameLine(g2, attribs, SplitCard.FUSE_RULE, "",
|
||||||
0, rightHalf.ch,
|
0, rightHalf.ch,
|
||||||
totalFuseBoxWidth - 2 * borderWidth, boxHeight);
|
totalFuseBoxWidth - 2 * borderWidth, boxHeight);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -388,11 +388,7 @@ public class CardView extends SimpleCardView {
|
||||||
this.name = card.getImageName();
|
this.name = card.getImageName();
|
||||||
this.displayName = card.getName();
|
this.displayName = card.getName();
|
||||||
this.displayFullName = fullCardName;
|
this.displayFullName = fullCardName;
|
||||||
if (game == null) {
|
this.rules = new ArrayList<>(card.getRules(game));
|
||||||
this.rules = new ArrayList<>(card.getRules());
|
|
||||||
} else {
|
|
||||||
this.rules = new ArrayList<>(card.getRules(game));
|
|
||||||
}
|
|
||||||
this.manaValue = card.getManaValue();
|
this.manaValue = card.getManaValue();
|
||||||
|
|
||||||
if (card instanceof Permanent) {
|
if (card instanceof Permanent) {
|
||||||
|
|
@ -627,7 +623,7 @@ public class CardView extends SimpleCardView {
|
||||||
PermanentToken permanentToken = (PermanentToken) object;
|
PermanentToken permanentToken = (PermanentToken) object;
|
||||||
this.rarity = Rarity.COMMON;
|
this.rarity = Rarity.COMMON;
|
||||||
this.expansionSetCode = permanentToken.getExpansionSetCode();
|
this.expansionSetCode = permanentToken.getExpansionSetCode();
|
||||||
this.rules = new ArrayList<>(permanentToken.getRules());
|
this.rules = new ArrayList<>(permanentToken.getRules(game));
|
||||||
this.type = permanentToken.getToken().getTokenType();
|
this.type = permanentToken.getToken().getTokenType();
|
||||||
} else if (object instanceof Emblem) {
|
} else if (object instanceof Emblem) {
|
||||||
this.mageObjectType = MageObjectType.EMBLEM;
|
this.mageObjectType = MageObjectType.EMBLEM;
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ class BaronVonCountTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
|| String.valueOf(spell.getToughness().getBaseValue()).contains(doomString)) {
|
|| String.valueOf(spell.getToughness().getBaseValue()).contains(doomString)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
for (String string : spell.getCard().getRules()) {
|
for (String string : spell.getCard().getRules(game)) {
|
||||||
if (string.contains(doomString)) {
|
if (string.contains(doomString)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ public class AdditionalCostRuleTest extends CardTestPlayerBase {
|
||||||
|
|
||||||
Card firewildBorderpost = playerA.getGraveyard().getCards(currentGame).iterator().next();
|
Card firewildBorderpost = playerA.getGraveyard().getCards(currentGame).iterator().next();
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String rule : firewildBorderpost.getRules()) {
|
for (String rule : firewildBorderpost.getRules(currentGame)) {
|
||||||
if (rule.startsWith("As an additional cost to cast")) {
|
if (rule.startsWith("As an additional cost to cast")) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import mage.constants.SpellAbilityType;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.ZoneChangeEvent;
|
import mage.game.events.ZoneChangeEvent;
|
||||||
|
import mage.util.CardUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -20,6 +21,8 @@ import java.util.UUID;
|
||||||
*/
|
*/
|
||||||
public abstract class SplitCard extends CardImpl implements CardWithHalves {
|
public abstract class SplitCard extends CardImpl implements CardWithHalves {
|
||||||
|
|
||||||
|
static public String FUSE_RULE = "Fuse (You may cast both halves from your hand.)";
|
||||||
|
|
||||||
protected Card leftHalfCard;
|
protected Card leftHalfCard;
|
||||||
protected Card rightHalfCard;
|
protected Card rightHalfCard;
|
||||||
|
|
||||||
|
|
@ -186,11 +189,29 @@ public abstract class SplitCard extends CardImpl implements CardWithHalves {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getRules() {
|
public List<String> getRules() {
|
||||||
List<String> rules = new ArrayList<>();
|
Abilities<Ability> sourceAbilities = this.getAbilities();
|
||||||
if (getSpellAbility().getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
|
List<String> res = CardUtil.getCardRulesWithAdditionalInfo(
|
||||||
rules.add("--------------------------------------------------------------------------\nFuse (You may cast one or both halves of this card from your hand.)");
|
this.getId(),
|
||||||
}
|
this.getName(),
|
||||||
return rules;
|
sourceAbilities,
|
||||||
|
sourceAbilities
|
||||||
|
);
|
||||||
|
res.add("--------------------------------------------------------------------------\n" + FUSE_RULE);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getRules(Game game) {
|
||||||
|
Abilities<Ability> sourceAbilities = this.getAbilities(game);
|
||||||
|
List<String> res = CardUtil.getCardRulesWithAdditionalInfo(
|
||||||
|
game,
|
||||||
|
this.getId(),
|
||||||
|
this.getName(),
|
||||||
|
sourceAbilities,
|
||||||
|
sourceAbilities
|
||||||
|
);
|
||||||
|
res.add("--------------------------------------------------------------------------\n" + FUSE_RULE);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package mage.cards.mock;
|
package mage.cards.mock;
|
||||||
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
|
import mage.abilities.Abilities;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.cards.SplitCard;
|
import mage.cards.SplitCard;
|
||||||
|
|
@ -9,6 +10,8 @@ import mage.cards.repository.CardInfo;
|
||||||
import mage.cards.repository.CardRepository;
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.constants.SpellAbilityType;
|
import mage.constants.SpellAbilityType;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.util.CardUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -109,4 +112,22 @@ public class MockSplitCard extends SplitCard {
|
||||||
private static String getRightHalfName(CardInfo card) {
|
private static String getRightHalfName(CardInfo card) {
|
||||||
return card.getName().split(" // ")[1];
|
return card.getName().split(" // ")[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getRules() {
|
||||||
|
// SplitCard adds additional fuse text to the card and to the database,
|
||||||
|
// so a MockSplitCard must ignore it (duplicate fix)
|
||||||
|
Abilities<Ability> sourceAbilities = this.getAbilities();
|
||||||
|
return CardUtil.getCardRulesWithAdditionalInfo(
|
||||||
|
this.getId(),
|
||||||
|
this.getName(),
|
||||||
|
sourceAbilities,
|
||||||
|
sourceAbilities
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getRules(Game game) {
|
||||||
|
return this.getRules();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,31 +190,14 @@ public class CardInfo {
|
||||||
|
|
||||||
int length = 0;
|
int length = 0;
|
||||||
List<String> rulesList = new ArrayList<>();
|
List<String> rulesList = new ArrayList<>();
|
||||||
if (card instanceof SplitCard) {
|
// All cards must use getRules logic, so no special code here for rules, example:
|
||||||
for (String rule : ((SplitCard) card).getLeftHalfCard().getRules()) {
|
// - split card: show all rules from both sides
|
||||||
length += rule.length();
|
// - mdf card: return main side's rules only (GUI can toggle it to another side)
|
||||||
rulesList.add(rule);
|
for (String rule : card.getRules()) {
|
||||||
}
|
length += rule.length();
|
||||||
for (String rule : ((SplitCard) card).getRightHalfCard().getRules()) {
|
rulesList.add(rule);
|
||||||
length += rule.length();
|
|
||||||
rulesList.add(rule);
|
|
||||||
}
|
|
||||||
for (String rule : card.getRules()) {
|
|
||||||
length += rule.length();
|
|
||||||
rulesList.add(rule);
|
|
||||||
}
|
|
||||||
} else if (card instanceof ModalDoubleFacesCard) {
|
|
||||||
// mdf card return main side's rules only (GUI can toggle it to another side)
|
|
||||||
for (String rule : card.getRules()) {
|
|
||||||
length += rule.length();
|
|
||||||
rulesList.add(rule);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (String rule : card.getRules()) {
|
|
||||||
length += rule.length();
|
|
||||||
rulesList.add(rule);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length > MAX_RULE_LENGTH) {
|
if (length > MAX_RULE_LENGTH) {
|
||||||
length = 0;
|
length = 0;
|
||||||
List<String> shortRules = new ArrayList<>();
|
List<String> shortRules = new ArrayList<>();
|
||||||
|
|
|
||||||
|
|
@ -263,13 +263,13 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
||||||
@Override
|
@Override
|
||||||
public List<String> getRules(Game game) {
|
public List<String> getRules(Game game) {
|
||||||
try {
|
try {
|
||||||
List<String> rules = getRules();
|
List<String> rules = super.getRules(game);
|
||||||
|
|
||||||
|
// add additional data for GUI
|
||||||
|
|
||||||
// info
|
// info
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
for (String data : info.values()) {
|
rules.addAll(info.values());
|
||||||
rules.add(data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ability hints
|
// ability hints
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue