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,14 +118,8 @@ public abstract class CardRenderer {
|
|||
public CardRenderer(CardView card) {
|
||||
// Set base parameters
|
||||
this.cardView = card;
|
||||
|
||||
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) {
|
||||
// Translate the textbox text and remove card hints
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.mage.card.arcane;
|
|||
|
||||
import mage.ObjectColor;
|
||||
import mage.cards.ArtRect;
|
||||
import mage.cards.SplitCard;
|
||||
import mage.constants.CardType;
|
||||
import mage.view.CardView;
|
||||
|
||||
|
|
@ -17,6 +18,9 @@ import java.util.List;
|
|||
*/
|
||||
public class ModernSplitCardRenderer extends ModernCardRenderer {
|
||||
|
||||
static String RULES_MARK_FUSE = "Fuse";
|
||||
static String RULES_MARK_AFTERMATH = "Aftermath";
|
||||
|
||||
private static class HalfCardProps {
|
||||
|
||||
int x, y, w, h, cw, ch;
|
||||
|
|
@ -61,8 +65,8 @@ public class ModernSplitCardRenderer extends ModernCardRenderer {
|
|||
rightHalf.name = cardView.getRightSplitName();
|
||||
leftHalf.name = cardView.getLeftSplitName();
|
||||
|
||||
isFuse = view.getRules().stream().anyMatch(rule -> rule.contains("Fuse"));
|
||||
isAftermath = view.getRightSplitRules().stream().anyMatch(rule -> rule.contains("Aftermath"));
|
||||
isFuse = view.getRules().stream().anyMatch(rule -> rule.contains(RULES_MARK_FUSE));
|
||||
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
|
||||
// they "rotate" in opposite directions making consquence and normal split cards
|
||||
|
|
@ -298,7 +302,7 @@ public class ModernSplitCardRenderer extends ModernCardRenderer {
|
|||
totalFuseBoxWidth, boxHeight,
|
||||
contentInset,
|
||||
borderPaint, boxColor);
|
||||
drawNameLine(g2, attribs, "Fuse (You may cast both halves from your hand)", "",
|
||||
drawNameLine(g2, attribs, SplitCard.FUSE_RULE, "",
|
||||
0, rightHalf.ch,
|
||||
totalFuseBoxWidth - 2 * borderWidth, boxHeight);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -388,11 +388,7 @@ public class CardView extends SimpleCardView {
|
|||
this.name = card.getImageName();
|
||||
this.displayName = card.getName();
|
||||
this.displayFullName = fullCardName;
|
||||
if (game == null) {
|
||||
this.rules = new ArrayList<>(card.getRules());
|
||||
} else {
|
||||
this.rules = new ArrayList<>(card.getRules(game));
|
||||
}
|
||||
this.manaValue = card.getManaValue();
|
||||
|
||||
if (card instanceof Permanent) {
|
||||
|
|
@ -627,7 +623,7 @@ public class CardView extends SimpleCardView {
|
|||
PermanentToken permanentToken = (PermanentToken) object;
|
||||
this.rarity = Rarity.COMMON;
|
||||
this.expansionSetCode = permanentToken.getExpansionSetCode();
|
||||
this.rules = new ArrayList<>(permanentToken.getRules());
|
||||
this.rules = new ArrayList<>(permanentToken.getRules(game));
|
||||
this.type = permanentToken.getToken().getTokenType();
|
||||
} else if (object instanceof Emblem) {
|
||||
this.mageObjectType = MageObjectType.EMBLEM;
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class BaronVonCountTriggeredAbility extends TriggeredAbilityImpl {
|
|||
|| String.valueOf(spell.getToughness().getBaseValue()).contains(doomString)) {
|
||||
return true;
|
||||
} else {
|
||||
for (String string : spell.getCard().getRules()) {
|
||||
for (String string : spell.getCard().getRules(game)) {
|
||||
if (string.contains(doomString)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class AdditionalCostRuleTest extends CardTestPlayerBase {
|
|||
|
||||
Card firewildBorderpost = playerA.getGraveyard().getCards(currentGame).iterator().next();
|
||||
boolean found = false;
|
||||
for (String rule : firewildBorderpost.getRules()) {
|
||||
for (String rule : firewildBorderpost.getRules(currentGame)) {
|
||||
if (rule.startsWith("As an additional cost to cast")) {
|
||||
found = true;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import mage.constants.SpellAbilityType;
|
|||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -20,6 +21,8 @@ import java.util.UUID;
|
|||
*/
|
||||
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 rightHalfCard;
|
||||
|
||||
|
|
@ -186,11 +189,29 @@ public abstract class SplitCard extends CardImpl implements CardWithHalves {
|
|||
|
||||
@Override
|
||||
public List<String> getRules() {
|
||||
List<String> rules = new ArrayList<>();
|
||||
if (getSpellAbility().getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
|
||||
rules.add("--------------------------------------------------------------------------\nFuse (You may cast one or both halves of this card from your hand.)");
|
||||
Abilities<Ability> sourceAbilities = this.getAbilities();
|
||||
List<String> res = CardUtil.getCardRulesWithAdditionalInfo(
|
||||
this.getId(),
|
||||
this.getName(),
|
||||
sourceAbilities,
|
||||
sourceAbilities
|
||||
);
|
||||
res.add("--------------------------------------------------------------------------\n" + FUSE_RULE);
|
||||
return res;
|
||||
}
|
||||
return rules;
|
||||
|
||||
@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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package mage.cards.mock;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Abilities;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.cards.SplitCard;
|
||||
|
|
@ -9,6 +10,8 @@ import mage.cards.repository.CardInfo;
|
|||
import mage.cards.repository.CardRepository;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SpellAbilityType;
|
||||
import mage.game.Game;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -109,4 +112,22 @@ public class MockSplitCard extends SplitCard {
|
|||
private static String getRightHalfName(CardInfo card) {
|
||||
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;
|
||||
List<String> rulesList = new ArrayList<>();
|
||||
if (card instanceof SplitCard) {
|
||||
for (String rule : ((SplitCard) card).getLeftHalfCard().getRules()) {
|
||||
length += rule.length();
|
||||
rulesList.add(rule);
|
||||
}
|
||||
for (String rule : ((SplitCard) card).getRightHalfCard().getRules()) {
|
||||
length += rule.length();
|
||||
rulesList.add(rule);
|
||||
}
|
||||
// All cards must use getRules logic, so no special code here for rules, example:
|
||||
// - split card: show all rules from both sides
|
||||
// - 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 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) {
|
||||
length = 0;
|
||||
List<String> shortRules = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -263,13 +263,13 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
@Override
|
||||
public List<String> getRules(Game game) {
|
||||
try {
|
||||
List<String> rules = getRules();
|
||||
List<String> rules = super.getRules(game);
|
||||
|
||||
// add additional data for GUI
|
||||
|
||||
// info
|
||||
if (info != null) {
|
||||
for (String data : info.values()) {
|
||||
rules.add(data);
|
||||
}
|
||||
rules.addAll(info.values());
|
||||
}
|
||||
|
||||
// ability hints
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue