From 4b16dc6ca4346434c7c4a4a77871575f052e4708 Mon Sep 17 00:00:00 2001 From: tool4EvEr Date: Sun, 2 Feb 2025 11:22:25 +0100 Subject: [PATCH] Reduce some View updates --- .../src/main/java/forge/game/GameAction.java | 2 +- .../main/java/forge/game/StaticEffect.java | 9 +++++--- .../src/main/java/forge/game/card/Card.java | 23 ++++++++----------- .../main/java/forge/game/card/CardView.java | 3 ++- .../main/java/forge/game/player/Player.java | 3 +-- .../cardsfolder/upcoming/pit_automaton.txt | 4 ++-- .../cardsfolder/upcoming/rangers_refueler.txt | 4 ++-- 7 files changed, 23 insertions(+), 25 deletions(-) diff --git a/forge-game/src/main/java/forge/game/GameAction.java b/forge-game/src/main/java/forge/game/GameAction.java index 2fe099b93c7..1e41bbad16e 100644 --- a/forge-game/src/main/java/forge/game/GameAction.java +++ b/forge-game/src/main/java/forge/game/GameAction.java @@ -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 diff --git a/forge-game/src/main/java/forge/game/StaticEffect.java b/forge-game/src/main/java/forge/game/StaticEffect.java index 30715222f57..0809f4cdf90 100644 --- a/forge-game/src/main/java/forge/game/StaticEffect.java +++ b/forge-game/src/main/java/forge/game/StaticEffect.java @@ -219,7 +219,9 @@ final CardCollectionView remove(List 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")) { @@ -275,6 +277,9 @@ final CardCollectionView remove(List layers) { } affectedCard.removeChangedSVars(getTimestamp(), ability.getId()); + + // need update for clean reapply + affectedCard.updateKeywordsCache(affectedCard.getCurrentState()); } if (layers.contains(StaticAbilityLayer.SETPT)) { @@ -311,8 +316,6 @@ final CardCollectionView remove(List layers) { affectedCard.removeCanBlockAdditional(getTimestamp()); } } - - affectedCard.updateAbilityTextForView(); // need to update keyword cache for clean reapply } return affectedCards; } diff --git a/forge-game/src/main/java/forge/game/card/Card.java b/forge-game/src/main/java/forge/game/card/Card.java index 6af9ea532e9..960235e8ab2 100644 --- a/forge-game/src/main/java/forge/game/card/Card.java +++ b/forge-game/src/main/java/forge/game/card/Card.java @@ -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() { @@ -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); @@ -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(); } } @@ -1838,7 +1837,6 @@ public final void setCounters(final Map allCounters) { } if (changed) { updateKeywords(); - updateAbilityTextForView(); } } @@ -1856,7 +1854,6 @@ public final void clearCounters() { } if (changed) { updateKeywords(); - updateAbilityTextForView(); } } @@ -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()) { @@ -4896,7 +4893,6 @@ public final void addChangedCardTraitsByText(Collection spells, changedCardTraitsByText.put(timestamp, staticId, new CardTraitChanges( spells, null, trigger, replacements, statics, true, false )); - // update view updateAbilityTextForView(); } @@ -5046,13 +5042,11 @@ public final void addChangedCardTraits(Collection 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(); } @@ -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); } @@ -5434,7 +5429,7 @@ public void updateChangedText() { getView().updateChangedTypes(this); updateManaCostForView(); - currentState.getView().updateAbilityText(this, currentState); + updateAbilityTextForView(); view.updateNonAbilityText(this); } @@ -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"); diff --git a/forge-game/src/main/java/forge/game/card/CardView.java b/forge-game/src/main/java/forge/game/card/CardView.java index 70504b8d957..dbaafb0606f 100644 --- a/forge-game/src/main/java/forge/game/card/CardView.java +++ b/forge-game/src/main/java/forge/game/card/CardView.java @@ -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)); @@ -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)); diff --git a/forge-game/src/main/java/forge/game/player/Player.java b/forge-game/src/main/java/forge/game/player/Player.java index 82b91ce630b..5d4f6731502 100644 --- a/forge-game/src/main/java/forge/game/player/Player.java +++ b/forge-game/src/main/java/forge/game/player/Player.java @@ -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) { @@ -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) { diff --git a/forge-gui/res/cardsfolder/upcoming/pit_automaton.txt b/forge-gui/res/cardsfolder/upcoming/pit_automaton.txt index 769824a230f..be8a8afa095 100644 --- a/forge-gui/res/cardsfolder/upcoming/pit_automaton.txt +++ b/forge-gui/res/cardsfolder/upcoming/pit_automaton.txt @@ -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. diff --git a/forge-gui/res/cardsfolder/upcoming/rangers_refueler.txt b/forge-gui/res/cardsfolder/upcoming/rangers_refueler.txt index 9e91fad0fb4..9a38d21690f 100644 --- a/forge-gui/res/cardsfolder/upcoming/rangers_refueler.txt +++ b/forge-gui/res/cardsfolder/upcoming/rangers_refueler.txt @@ -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