Merge pull request #9155 from Jetz72/fixes20251112

Automatically swap flavor names into oracle text
This commit is contained in:
Jetz72
2025-11-13 08:33:01 -06:00
committed by GitHub
2 changed files with 21 additions and 6 deletions

View File

@@ -1,10 +1,12 @@
package forge.card;
import forge.card.mana.ManaCost;
import forge.util.Lang;
import org.apache.commons.lang3.StringUtils;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
//
@@ -185,7 +187,25 @@ final class CardFace implements ICardFace, Cloneable {
}
void assignMissingFieldsToVariant(CardFace variant) {
if(variant.oracleText == null) variant.oracleText = this.oracleText;
if(variant.oracleText == null) {
if(variant.flavorName != null && this.oracleText != null) {
try {
Lang lang = Lang.getInstance();
//Rudimentary name replacement. Can't do pronouns, ability words, or flavored keywords. Need to define variant text manually for that.
//Regex here checks for the name following either a word boundary or a literal "\n" string, since those haven't yet been converted to line breaks.
String flavoredText = this.oracleText.replaceAll("(?<=\\b|\\\\n)" + this.name + "\\b", variant.flavorName);
flavoredText = flavoredText.replaceAll("(?<=\\b|\\\\n)" + lang.getNickName(this.name) + "\\b", lang.getNickName(variant.flavorName));
variant.oracleText = flavoredText;
}
catch (PatternSyntaxException ignored) {
// Old versions of Android are weird about patterns sometimes. I don't *think* this is such a case but
// the documentation is unreliable. May be worth removing this once we're sure it's not a problem.
variant.oracleText = this.oracleText;
}
}
else
variant.oracleText = this.oracleText;
}
if(variant.manaCost == null) variant.manaCost = this.manaCost;
if(variant.color == null) variant.color = ColorSet.fromManaCost(variant.manaCost);

View File

@@ -504,16 +504,11 @@ public final class CardRules implements ICardCharacteristics {
CardFace variantMain = ((CardFace) mainPart).getOrCreateFunctionalVariant(variantName);
variantMain.setFlavorName(nameParts[0]);
//Rudimentary name replacement. Can't do nicknames, pronouns, ability words, or flavored keywords. Need to define variants manually for that.
if(mainPart.getOracleText().contains(mainPart.getName()))
variantMain.setOracleText(mainPart.getOracleText().replace(mainPart.getName(), nameParts[0]));
((CardFace) mainPart).assignMissingFieldsToVariant(variantMain);
if(otherPart != null) {
CardFace variantOther = ((CardFace) otherPart).getOrCreateFunctionalVariant(variantName);
variantOther.setFlavorName(nameParts[1]);
if(otherPart.getOracleText().contains(otherPart.getName()))
variantMain.setOracleText(otherPart.getOracleText().replace(otherPart.getName(), nameParts[1]));
((CardFace) otherPart).assignMissingFieldsToVariant(variantOther);
}