Reduce some View updates (#6966)

This commit is contained in:
tool4ever
2025-02-02 18:52:20 +01:00
committed by GitHub
parent 309e36827c
commit a8488502e7
7 changed files with 23 additions and 25 deletions

View File

@@ -1278,7 +1278,7 @@ public class GameAction {
c.updateNameforView(); c.updateNameforView();
c.updatePowerToughnessForView(); c.updatePowerToughnessForView();
c.updateTypesForView(); c.updateTypesForView();
c.updateAbilityTextForView(); // only update keywords and text for view to avoid flickering c.updateKeywords();
} }
// TODO filter out old copies from zone change // TODO filter out old copies from zone change

View File

@@ -219,7 +219,9 @@ public class StaticEffect {
if (layers.contains(StaticAbilityLayer.TEXT)) { if (layers.contains(StaticAbilityLayer.TEXT)) {
// Revert changed color words // Revert changed color words
affectedCard.removeChangedTextColorWord(getTimestamp(), ability.getId()); if (hasParam("ChangeColorWordsTo")) {
affectedCard.removeChangedTextColorWord(getTimestamp(), ability.getId());
}
// remove changed name // remove changed name
if (hasParam("SetName") || hasParam("AddNames")) { if (hasParam("SetName") || hasParam("AddNames")) {
@@ -275,6 +277,9 @@ public class StaticEffect {
} }
affectedCard.removeChangedSVars(getTimestamp(), ability.getId()); affectedCard.removeChangedSVars(getTimestamp(), ability.getId());
// need update for clean reapply
affectedCard.updateKeywordsCache(affectedCard.getCurrentState());
} }
if (layers.contains(StaticAbilityLayer.SETPT)) { if (layers.contains(StaticAbilityLayer.SETPT)) {
@@ -311,8 +316,6 @@ public class StaticEffect {
affectedCard.removeCanBlockAdditional(getTimestamp()); affectedCard.removeCanBlockAdditional(getTimestamp());
} }
} }
affectedCard.updateAbilityTextForView(); // need to update keyword cache for clean reapply
} }
return affectedCards; return affectedCards;
} }

View File

@@ -600,8 +600,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
// The following methods are used to selectively update certain view components (text, // The following methods are used to selectively update certain view components (text,
// P/T, card types) in order to avoid card flickering due to aggressive full update // P/T, card types) in order to avoid card flickering due to aggressive full update
public void updateAbilityTextForView() { public void updateAbilityTextForView() {
updateKeywords(); // does call update Ability text view.getCurrentState().updateAbilityText(this, getCurrentState());
//view.getCurrentState().updateAbilityText(this, getCurrentState());
} }
public void updateManaCostForView() { public void updateManaCostForView() {
@@ -1690,8 +1689,8 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
} }
if (newValue <= 0) { if (newValue <= 0) {
removeCounterTimestamp(counterType); removeCounterTimestamp(counterType);
} else if (addCounterTimestamp(counterType)) { } else if (addCounterTimestamp(counterType, false)) {
updateAbilityTextForView(); updateKeywords();
} }
if (table != null) { if (table != null) {
table.put(source, this, counterType, addAmount); table.put(source, this, counterType, addAmount);
@@ -1789,8 +1788,8 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
view.updateCounters(this); view.updateCounters(this);
if (newValue <= 0) { if (newValue <= 0) {
if (removeCounterTimestamp(counterName)) { if (removeCounterTimestamp(counterName, false)) {
updateAbilityTextForView(); updateKeywords();
} }
} }
@@ -1838,7 +1837,6 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
} }
if (changed) { if (changed) {
updateKeywords(); updateKeywords();
updateAbilityTextForView();
} }
} }
@@ -1856,7 +1854,6 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
} }
if (changed) { if (changed) {
updateKeywords(); updateKeywords();
updateAbilityTextForView();
} }
} }
@@ -2169,7 +2166,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
public void setCurrentRoom(String room) { public void setCurrentRoom(String room) {
currentRoom = room; currentRoom = room;
view.updateCurrentRoom(this); view.updateCurrentRoom(this);
view.getCurrentState().updateAbilityText(this, getCurrentState()); updateAbilityTextForView();
} }
public boolean isInLastRoom() { public boolean isInLastRoom() {
for (final Trigger t : getTriggers()) { for (final Trigger t : getTriggers()) {
@@ -4896,7 +4893,6 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
changedCardTraitsByText.put(timestamp, staticId, new CardTraitChanges( changedCardTraitsByText.put(timestamp, staticId, new CardTraitChanges(
spells, null, trigger, replacements, statics, true, false spells, null, trigger, replacements, statics, true, false
)); ));
// update view
updateAbilityTextForView(); updateAbilityTextForView();
} }
@@ -5046,13 +5042,11 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
changedCardTraits.put(timestamp, staticId, new CardTraitChanges( changedCardTraits.put(timestamp, staticId, new CardTraitChanges(
spells, removedAbilities, trigger, replacements, statics, removeAll, removeNonMana spells, removedAbilities, trigger, replacements, statics, removeAll, removeNonMana
)); ));
// update view
updateAbilityTextForView(); updateAbilityTextForView();
} }
public final void addChangedCardTraits(CardTraitChanges ctc, long timestamp, long staticId) { public final void addChangedCardTraits(CardTraitChanges ctc, long timestamp, long staticId) {
changedCardTraits.put(timestamp, staticId, ctc); changedCardTraits.put(timestamp, staticId, ctc);
// update view
updateAbilityTextForView(); updateAbilityTextForView();
} }
@@ -5144,6 +5138,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
public final void updateKeywords() { public final void updateKeywords() {
getCurrentState().getView().updateKeywords(this, getCurrentState()); getCurrentState().getView().updateKeywords(this, getCurrentState());
// for Zilortha
getView().updateLethalDamage(this); getView().updateLethalDamage(this);
} }
@@ -5434,7 +5429,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
getView().updateChangedTypes(this); getView().updateChangedTypes(this);
updateManaCostForView(); updateManaCostForView();
currentState.getView().updateAbilityText(this, currentState); updateAbilityTextForView();
view.updateNonAbilityText(this); view.updateNonAbilityText(this);
} }
@@ -6796,7 +6791,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
public void setClassLevel(int level) { public void setClassLevel(int level) {
classLevel = level; classLevel = level;
view.updateClassLevel(this); view.updateClassLevel(this);
view.getCurrentState().updateAbilityText(this, getCurrentState()); updateAbilityTextForView();
} }
public boolean isClassCard() { public boolean isClassCard() {
return getType().hasStringType("Class"); return getType().hasStringType("Class");

View File

@@ -1603,7 +1603,9 @@ public class CardView extends GameEntityView {
} }
void updateKeywords(Card c, CardState state) { void updateKeywords(Card c, CardState state) {
c.updateKeywordsCache(state); c.updateKeywordsCache(state);
// deeper check for Idris
set(TrackableProperty.HasAnnihilator, c.hasKeyword(Keyword.ANNIHILATOR, state) || state.getTriggers().anyMatch(t -> t.isKeyword(Keyword.ANNIHILATOR))); set(TrackableProperty.HasAnnihilator, c.hasKeyword(Keyword.ANNIHILATOR, state) || state.getTriggers().anyMatch(t -> t.isKeyword(Keyword.ANNIHILATOR)));
set(TrackableProperty.HasWard, c.hasKeyword(Keyword.WARD, state) || state.getTriggers().anyMatch(t -> t.isKeyword(Keyword.WARD)));
set(TrackableProperty.HasDeathtouch, c.hasKeyword(Keyword.DEATHTOUCH, state)); set(TrackableProperty.HasDeathtouch, c.hasKeyword(Keyword.DEATHTOUCH, state));
set(TrackableProperty.HasToxic, c.hasKeyword(Keyword.TOXIC, state)); set(TrackableProperty.HasToxic, c.hasKeyword(Keyword.TOXIC, state));
set(TrackableProperty.HasDevoid, c.hasKeyword(Keyword.DEVOID, state)); set(TrackableProperty.HasDevoid, c.hasKeyword(Keyword.DEVOID, state));
@@ -1617,7 +1619,6 @@ public class CardView extends GameEntityView {
set(TrackableProperty.HasFear, c.hasKeyword(Keyword.FEAR, state)); set(TrackableProperty.HasFear, c.hasKeyword(Keyword.FEAR, state));
set(TrackableProperty.HasHexproof, c.hasKeyword(Keyword.HEXPROOF, state)); set(TrackableProperty.HasHexproof, c.hasKeyword(Keyword.HEXPROOF, state));
set(TrackableProperty.HasHorsemanship, c.hasKeyword(Keyword.HORSEMANSHIP, state)); set(TrackableProperty.HasHorsemanship, c.hasKeyword(Keyword.HORSEMANSHIP, state));
set(TrackableProperty.HasWard, c.hasKeyword(Keyword.WARD, state) || state.getTriggers().anyMatch(t -> t.isKeyword(Keyword.WARD)));
set(TrackableProperty.HasWither, c.hasKeyword(Keyword.WITHER, state)); set(TrackableProperty.HasWither, c.hasKeyword(Keyword.WITHER, state));
set(TrackableProperty.HasIndestructible, c.hasKeyword(Keyword.INDESTRUCTIBLE, state)); set(TrackableProperty.HasIndestructible, c.hasKeyword(Keyword.INDESTRUCTIBLE, state));
set(TrackableProperty.HasIntimidate, c.hasKeyword(Keyword.INTIMIDATE, state)); set(TrackableProperty.HasIntimidate, c.hasKeyword(Keyword.INTIMIDATE, state));

View File

@@ -3615,7 +3615,6 @@ public class Player extends GameEntity implements Comparable<Player> {
return; return;
final PlayerZone com = getZone(ZoneType.Command); final PlayerZone com = getZone(ZoneType.Command);
keywordEffect.setText(""); keywordEffect.setText("");
keywordEffect.updateAbilityTextForView();
boolean headerAdded = false; boolean headerAdded = false;
StringBuilder kw = new StringBuilder(); StringBuilder kw = new StringBuilder();
for (KeywordInterface k : keywords) { for (KeywordInterface k : keywords) {
@@ -3627,8 +3626,8 @@ public class Player extends GameEntity implements Comparable<Player> {
} }
if (!kw.toString().isEmpty()) { if (!kw.toString().isEmpty()) {
keywordEffect.setText(trimKeywords(kw.toString())); keywordEffect.setText(trimKeywords(kw.toString()));
keywordEffect.updateAbilityTextForView();
} }
keywordEffect.updateAbilityTextForView();
this.updateZoneForView(com); this.updateZoneForView(com);
} }
public String trimKeywords(String keywordTexts) { public String trimKeywords(String keywordTexts) {

View File

@@ -4,6 +4,6 @@ Types:Artifact Creature Construct
PT:0/4 PT:0/4
K:Defender K:Defender
A:AB$ Mana | Cost$ T | Produced$ C | Amount$ 2 | RestrictValid$ Activated | SpellDescription$ Add {C}{C}. Spend this mana only to activate abilities. A:AB$ Mana | Cost$ T | Produced$ C | Amount$ 2 | RestrictValid$ Activated | SpellDescription$ Add {C}{C}. Spend this mana only to activate abilities.
A:AB$ DelayedTrigger | Cost$ 2 T | AILogic$ SpellCopy | Mode$ AbilityCast | ValidSA$ Activated.Exhaust | ValidActivatingPlayer$ You | ThisTurn$ True | Execute$ EffTrigCopy | SpellDescription$ When you next activate an exhaust ability this turn, copy it. You may choose new targets for the copy. A:AB$ DelayedTrigger | Cost$ 2 T | AILogic$ SpellCopy | Mode$ AbilityCast | ValidSA$ Activated.Exhaust+nonManaAbility | ValidActivatingPlayer$ You | ThisTurn$ True | Execute$ EffTrigCopy | SpellDescription$ When you next activate an exhaust ability that isn't a mana ability this turn, copy it. You may choose new targets for the copy.
SVar:EffTrigCopy:DB$ CopySpellAbility | Defined$ TriggeredSpellAbility | MayChooseTarget$ True SVar:EffTrigCopy:DB$ CopySpellAbility | Defined$ TriggeredSpellAbility | MayChooseTarget$ True
Oracle:Defender\n{T}: Add {C}{C}. Spend this mana only to activate abilities.\n{2}, {T}: When you next activate an exhaust ability this turn, copy it. You may choose new targets for the copy. Oracle:Defender\n{T}: Add {C}{C}. Spend this mana only to activate abilities.\n{2}, {T}: When you next activate an exhaust ability that isn't a mana ability this turn, copy it. You may choose new targets for the copy.

View File

@@ -2,8 +2,8 @@ Name:Rangers' Refueler
ManaCost:1 U ManaCost:1 U
Types:Artifact Vehicle Types:Artifact Vehicle
PT:3/3 PT:3/3
T:Mode$ AbilityCast | ValidActivatingPlayer$ You | ValidSA$ Activated.Exhaust | TriggerZones$ Battlefield | Execute$ TrigToken | TriggerDescription$ Whenever you activate an exhaust ability, create a 1/1 colorless Thopter artifact creature token with flying. T:Mode$ AbilityCast | ValidActivatingPlayer$ You | ValidSA$ Activated.Exhaust | TriggerZones$ Battlefield | Execute$ TrigDraw | TriggerDescription$ Whenever you activate an exhaust ability, draw a card.
SVar:TrigToken:DB$ Token | TokenAmount$ 1 | TokenScript$ c_1_1_a_thopter_flying | TokenOwner$ You SVar:TrigDraw:DB$ Draw
A:AB$ Animate | Cost$ 4 | Defined$ Self | Types$ Artifact,Creature | Exhaust$ True | Duration$ Permanent | SubAbility$ DBPutCounter | SpellDescription$ This Vehicle becomes an artifact creature. Put a +1/+1 counter on it. (Activate each exhaust ability only once.) A:AB$ Animate | Cost$ 4 | Defined$ Self | Types$ Artifact,Creature | Exhaust$ True | Duration$ Permanent | SubAbility$ DBPutCounter | SpellDescription$ This Vehicle becomes an artifact creature. Put a +1/+1 counter on it. (Activate each exhaust ability only once.)
SVar:DBPutCounter:DB$ PutCounter | Defined$ Self | CounterType$ P1P1 | CounterNum$ 1 SVar:DBPutCounter:DB$ PutCounter | Defined$ Self | CounterType$ P1P1 | CounterNum$ 1
K:Crew:1 K:Crew:1