Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce some View updates #6966

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion forge-game/src/main/java/forge/game/GameAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ public boolean visit(final Card c) {
c.updateNameforView();
c.updatePowerToughnessForView();
c.updateTypesForView();
c.updateAbilityTextForView(); // only update keywords and text for view to avoid flickering
c.updateKeywords();
}

// TODO filter out old copies from zone change
Expand Down
9 changes: 6 additions & 3 deletions forge-game/src/main/java/forge/game/StaticEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ final CardCollectionView remove(List<StaticAbilityLayer> layers) {

if (layers.contains(StaticAbilityLayer.TEXT)) {
// Revert changed color words
affectedCard.removeChangedTextColorWord(getTimestamp(), ability.getId());
if (hasParam("ChangeColorWordsTo")) {
affectedCard.removeChangedTextColorWord(getTimestamp(), ability.getId());
}

// remove changed name
if (hasParam("SetName") || hasParam("AddNames")) {
Expand Down Expand Up @@ -275,6 +277,9 @@ final CardCollectionView remove(List<StaticAbilityLayer> layers) {
}

affectedCard.removeChangedSVars(getTimestamp(), ability.getId());

// need update for clean reapply
affectedCard.updateKeywordsCache(affectedCard.getCurrentState());
}

if (layers.contains(StaticAbilityLayer.SETPT)) {
Expand Down Expand Up @@ -311,8 +316,6 @@ final CardCollectionView remove(List<StaticAbilityLayer> layers) {
affectedCard.removeCanBlockAdditional(getTimestamp());
}
}

affectedCard.updateAbilityTextForView(); // need to update keyword cache for clean reapply
}
return affectedCards;
}
Expand Down
23 changes: 9 additions & 14 deletions forge-game/src/main/java/forge/game/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,7 @@ public void updateStateForView() {
// 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
public void updateAbilityTextForView() {
updateKeywords(); // does call update Ability text
//view.getCurrentState().updateAbilityText(this, getCurrentState());
view.getCurrentState().updateAbilityText(this, getCurrentState());
}

public void updateManaCostForView() {
Expand Down Expand Up @@ -1690,8 +1689,8 @@ public void addCounterInternal(final CounterType counterType, final int n, final
}
if (newValue <= 0) {
removeCounterTimestamp(counterType);
} else if (addCounterTimestamp(counterType)) {
updateAbilityTextForView();
} else if (addCounterTimestamp(counterType, false)) {
updateKeywords();
}
if (table != null) {
table.put(source, this, counterType, addAmount);
Expand Down Expand Up @@ -1789,8 +1788,8 @@ public final int subtractCounter(final CounterType counterName, final int n, fin
view.updateCounters(this);

if (newValue <= 0) {
if (removeCounterTimestamp(counterName)) {
updateAbilityTextForView();
if (removeCounterTimestamp(counterName, false)) {
updateKeywords();
}
}

Expand Down Expand Up @@ -1838,7 +1837,6 @@ public final void setCounters(final Map<CounterType, Integer> allCounters) {
}
if (changed) {
updateKeywords();
updateAbilityTextForView();
}
}

Expand All @@ -1856,7 +1854,6 @@ public final void clearCounters() {
}
if (changed) {
updateKeywords();
updateAbilityTextForView();
}
}

Expand Down Expand Up @@ -2169,7 +2166,7 @@ public String getCurrentRoom() {
public void setCurrentRoom(String room) {
currentRoom = room;
view.updateCurrentRoom(this);
view.getCurrentState().updateAbilityText(this, getCurrentState());
updateAbilityTextForView();
}
public boolean isInLastRoom() {
for (final Trigger t : getTriggers()) {
Expand Down Expand Up @@ -4896,7 +4893,6 @@ public final void addChangedCardTraitsByText(Collection<SpellAbility> spells,
changedCardTraitsByText.put(timestamp, staticId, new CardTraitChanges(
spells, null, trigger, replacements, statics, true, false
));
// update view
updateAbilityTextForView();
}

Expand Down Expand Up @@ -5046,13 +5042,11 @@ public final void addChangedCardTraits(Collection<SpellAbility> spells, Collecti
changedCardTraits.put(timestamp, staticId, new CardTraitChanges(
spells, removedAbilities, trigger, replacements, statics, removeAll, removeNonMana
));
// update view
updateAbilityTextForView();
}

public final void addChangedCardTraits(CardTraitChanges ctc, long timestamp, long staticId) {
changedCardTraits.put(timestamp, staticId, ctc);
// update view
updateAbilityTextForView();
}

Expand Down Expand Up @@ -5144,6 +5138,7 @@ public final boolean hasKeyword(String keyword, CardState state) {

public final void updateKeywords() {
getCurrentState().getView().updateKeywords(this, getCurrentState());
// for Zilortha
getView().updateLethalDamage(this);
}

Expand Down Expand Up @@ -5434,7 +5429,7 @@ public void updateChangedText() {
getView().updateChangedTypes(this);
updateManaCostForView();

currentState.getView().updateAbilityText(this, currentState);
updateAbilityTextForView();
view.updateNonAbilityText(this);
}

Expand Down Expand Up @@ -6796,7 +6791,7 @@ public final int getClassLevel() {
public void setClassLevel(int level) {
classLevel = level;
view.updateClassLevel(this);
view.getCurrentState().updateAbilityText(this, getCurrentState());
updateAbilityTextForView();
}
public boolean isClassCard() {
return getType().hasStringType("Class");
Expand Down
3 changes: 2 additions & 1 deletion forge-game/src/main/java/forge/game/card/CardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,9 @@ void updateAbilityText(Card c, CardState state) {
}
void updateKeywords(Card c, CardState 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.HasWard, c.hasKeyword(Keyword.WARD, state) || state.getTriggers().anyMatch(t -> t.isKeyword(Keyword.WARD)));
set(TrackableProperty.HasDeathtouch, c.hasKeyword(Keyword.DEATHTOUCH, state));
set(TrackableProperty.HasToxic, c.hasKeyword(Keyword.TOXIC, state));
set(TrackableProperty.HasDevoid, c.hasKeyword(Keyword.DEVOID, state));
Expand All @@ -1617,7 +1619,6 @@ void updateKeywords(Card c, CardState state) {
set(TrackableProperty.HasFear, c.hasKeyword(Keyword.FEAR, state));
set(TrackableProperty.HasHexproof, c.hasKeyword(Keyword.HEXPROOF, 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.HasIndestructible, c.hasKeyword(Keyword.INDESTRUCTIBLE, state));
set(TrackableProperty.HasIntimidate, c.hasKeyword(Keyword.INTIMIDATE, state));
Expand Down
3 changes: 1 addition & 2 deletions forge-game/src/main/java/forge/game/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -3615,7 +3615,6 @@ public void updateKeywordCardAbilityText() {
return;
final PlayerZone com = getZone(ZoneType.Command);
keywordEffect.setText("");
keywordEffect.updateAbilityTextForView();
boolean headerAdded = false;
StringBuilder kw = new StringBuilder();
for (KeywordInterface k : keywords) {
Expand All @@ -3627,8 +3626,8 @@ public void updateKeywordCardAbilityText() {
}
if (!kw.toString().isEmpty()) {
keywordEffect.setText(trimKeywords(kw.toString()));
keywordEffect.updateAbilityTextForView();
}
keywordEffect.updateAbilityTextForView();
this.updateZoneForView(com);
}
public String trimKeywords(String keywordTexts) {
Expand Down
4 changes: 2 additions & 2 deletions forge-gui/res/cardsfolder/upcoming/pit_automaton.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Types:Artifact Creature Construct
PT:0/4
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$ 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
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.
4 changes: 2 additions & 2 deletions forge-gui/res/cardsfolder/upcoming/rangers_refueler.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Name:Rangers' Refueler
ManaCost:1 U
Types:Artifact Vehicle
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.
SVar:TrigToken:DB$ Token | TokenAmount$ 1 | TokenScript$ c_1_1_a_thopter_flying | TokenOwner$ You
T:Mode$ AbilityCast | ValidActivatingPlayer$ You | ValidSA$ Activated.Exhaust | TriggerZones$ Battlefield | Execute$ TrigDraw | TriggerDescription$ Whenever you activate an exhaust ability, draw a card.
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.)
SVar:DBPutCounter:DB$ PutCounter | Defined$ Self | CounterType$ P1P1 | CounterNum$ 1
K:Crew:1
Expand Down