Little fixes and code refactor

This commit is contained in:
Oleg Agafonov 2020-08-29 18:09:44 +04:00
parent c67e937dfb
commit ab8a4eb26a
8 changed files with 71 additions and 98 deletions

View file

@ -1,13 +1,14 @@
package mage.abilities.effects;
import java.util.ArrayList;
import java.util.Arrays;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.constants.Outcome;
import mage.target.targetpointer.TargetPointer;
import mage.util.CardUtil;
import java.util.ArrayList;
import java.util.Arrays;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -56,42 +57,41 @@ public class Effects extends ArrayList<Effect> {
nextRule = concatPrefix + " " + nextRule;
}
if (nextRule != null) {
//check if nextRule is a new sentence or not.
if (nextRule.startsWith("and ") || nextRule.startsWith("with ") || nextRule.startsWith("then ")) {
//check if nextRule is a new sentence or not.
if (nextRule.startsWith("and ") || nextRule.startsWith("with ") || nextRule.startsWith("then ")) {
endString = " ";
} else if (nextRule.startsWith(",") || nextRule.startsWith(" ")) {
endString = "";
// nextRule determined to be a new sentence, now check ending of lastRule
} else if (lastRule != null && lastRule.length() > 3) {
//check if lastRule already has appropriate punctuation, if so, add a space.
if (lastRule.endsWith(".\"")
|| lastRule.endsWith(".)")
|| lastRule.endsWith(".)</i>")
|| lastRule.endsWith(".")) {
endString = " ";
} else if (nextRule.startsWith(",") || nextRule.startsWith(" ")) {
endString = "";
// nextRule determined to be a new sentence, now check ending of lastRule
} else if (lastRule != null && lastRule.length() > 3) {
//check if lastRule already has appropriate punctuation, if so, add a space.
if (lastRule.endsWith(".\"")
|| lastRule.endsWith(".)")
|| lastRule.endsWith(".)</i>")
|| lastRule.endsWith(".")) {
endString = " ";
// if lastRule does not have appropriate punctuation, add the default ". "
} else if (!lastRule.endsWith(".") && !lastRule.endsWith("<br>")) {
endString = ". ";
}
if (nextRule.length() > 3) {
nextRule = Character.toUpperCase(nextRule.charAt(0)) + nextRule.substring(1);
}
// if lastRule does not have appropriate punctuation, add the default ". "
} else if (!lastRule.endsWith(".") && !lastRule.endsWith("<br>")) {
endString = ". ";
}
String currentRule = endString + nextRule;
// fix dot in the combined effect like IfDoCost
if (sbText.length() > 0 && currentRule.length() > 0) {
boolean prevTextEndsWithDot = sbText.charAt(sbText.length() - 1) == '.';
boolean currentTextStartsWithDot = currentRule.startsWith(",") || currentRule.startsWith(".");
if (prevTextEndsWithDot && currentTextStartsWithDot) {
sbText.delete(sbText.length() - 1, sbText.length());
}
if (nextRule.length() > 3) {
nextRule = Character.toUpperCase(nextRule.charAt(0)) + nextRule.substring(1);
}
sbText.append(currentRule);
}
String currentRule = endString + nextRule;
// fix dot in the combined effect like IfDoCost
if (sbText.length() > 0 && currentRule.length() > 0) {
boolean prevTextEndsWithDot = sbText.charAt(sbText.length() - 1) == '.';
boolean currentTextStartsWithDot = currentRule.startsWith(",") || currentRule.startsWith(".");
if (prevTextEndsWithDot && currentTextStartsWithDot) {
sbText.delete(sbText.length() - 1, sbText.length());
}
}
sbText.append(currentRule);
lastRule = nextRule;
}