Refactor: moved flavor word from effects list to ability/mode;

This commit is contained in:
Oleg Agafonov 2021-06-30 08:57:06 +04:00
parent 2d1e11dfa9
commit 6dafb3ad81
13 changed files with 52 additions and 40 deletions

View file

@ -466,7 +466,13 @@ public interface Ability extends Controllable, Serializable {
*/
Ability setAbilityWord(AbilityWord abilityWord);
Ability setFlavorWord(String flavorWord);
/**
* Set Flavor word for current mode
*
* @param flavorWord
* @return
*/
Ability withFlavorWord(String flavorWord);
/**
* Creates the message about the ability casting/triggering/activating to

View file

@ -60,7 +60,6 @@ public abstract class AbilityImpl implements Ability {
protected Zone zone;
protected String name;
protected AbilityWord abilityWord;
protected String flavorWord;
protected boolean usesStack = true;
protected boolean ruleAtTheTop = false;
protected boolean ruleVisible = true;
@ -118,7 +117,6 @@ public abstract class AbilityImpl implements Ability {
this.ruleAdditionalCostsVisible = ability.ruleAdditionalCostsVisible;
this.worksFaceDown = ability.worksFaceDown;
this.abilityWord = ability.abilityWord;
this.flavorWord = ability.flavorWord;
this.sourceObjectZoneChangeCounter = ability.sourceObjectZoneChangeCounter;
this.canFizzle = ability.canFizzle;
this.targetAdjuster = ability.targetAdjuster;
@ -805,8 +803,6 @@ public abstract class AbilityImpl implements Ability {
String prefix;
if (abilityWord != null) {
prefix = abilityWord.formatWord();
} else if (flavorWord != null) {
prefix = "<i>" + flavorWord + "</i> &mdash; ";
} else {
prefix = null;
}
@ -1072,8 +1068,9 @@ public abstract class AbilityImpl implements Ability {
return this;
}
public Ability setFlavorWord(String flavorWord) {
this.flavorWord = flavorWord;
@Override
public Ability withFlavorWord(String flavorWord) {
this.getModes().getMode().withFlavorWord(flavorWord);
return this;
}

View file

@ -16,6 +16,7 @@ public class Mode implements Serializable {
protected UUID id;
protected final Targets targets;
protected final Effects effects;
protected String flavorWord;
public Mode() {
this((Effect) null);
@ -34,6 +35,7 @@ public class Mode implements Serializable {
this.id = mode.id;
this.targets = mode.targets.copy();
this.effects = mode.effects.copy();
this.flavorWord = mode.flavorWord;
}
public UUID setRandomId() {
@ -71,8 +73,18 @@ public class Mode implements Serializable {
effects.add(effect);
}
public Mode setFlavorWord(String flavorWord) {
effects.setFlavorWord(flavorWord);
public String getFlavorWord() {
return flavorWord;
}
/**
* Set Flavor word to the mode (same as ability/ancher words, but uses for lore/info and represents a possible choices)
*
* @param flavorWord
* @return
*/
public Mode withFlavorWord(String flavorWord) {
this.flavorWord = flavorWord;
return this;
}
}

View file

@ -14,14 +14,11 @@ import java.util.Arrays;
*/
public class Effects extends ArrayList<Effect> {
private String flavorWord = null;
public Effects(Effect... effects) {
this.addAll(Arrays.asList(effects));
}
public Effects(final Effects effects) {
this.flavorWord = effects.flavorWord;
for (Effect effect : effects) {
this.add(effect.copy());
}
@ -64,7 +61,6 @@ public class Effects extends ArrayList<Effect> {
}
}
//check if nextRule is a new sentence or not.
if (nextRule.startsWith("and ") || nextRule.startsWith("with ") || nextRule.startsWith("then ")) {
endString = " ";
@ -100,10 +96,9 @@ public class Effects extends ArrayList<Effect> {
sbText.append(currentRule);
lastRule = nextRule;
}
//add punctuation to very last rule.
// add punctuation to very last rule.
if (lastRule != null && lastRule.length() > 3
&& !lastRule.endsWith(".")
&& !lastRule.endsWith("\"")
@ -113,11 +108,12 @@ public class Effects extends ArrayList<Effect> {
sbText.append('.');
}
if (flavorWord != null) {
return "<i>" + flavorWord + "</i> &mdash; " + CardUtil.getTextWithFirstCharUpperCase(sbText.toString());
}
return sbText.toString();
// flavor word
if (mode.getFlavorWord() != null) {
return "<i>" + mode.getFlavorWord() + "</i> &mdash; " + CardUtil.getTextWithFirstCharUpperCase(sbText.toString());
};
return sbText.toString();
}
public boolean hasOutcome(Ability source, Outcome outcome) {
@ -195,8 +191,4 @@ public class Effects extends ArrayList<Effect> {
effect.setValue(key, value);
}
}
public void setFlavorWord(String flavorWord) {
this.flavorWord = flavorWord;
}
}

View file

@ -497,7 +497,7 @@ public class StackAbility extends StackObjectImpl implements Ability {
}
@Override
public Ability setFlavorWord(String flavorWord) {
public Ability withFlavorWord(String flavorWord) {
throw new UnsupportedOperationException("Not supported.");
}