Skip to content

Commit

Permalink
Card: moved some getter/setter into a copyFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanmac committed Nov 17, 2024
1 parent 14b6102 commit 8121d15
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 54 deletions.
8 changes: 1 addition & 7 deletions forge-ai/src/main/java/forge/ai/simulation/GameCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,7 @@ private void addCard(Game newGame, ZoneType zone, Card c, Player aiPlayer) {
newCard.setDamage(c.getDamage());
newCard.setDamageReceivedThisTurn(c.getDamageReceivedThisTurn());

newCard.setChangedCardColors(c.getChangedCardColorsTable());
newCard.setChangedCardColorsCharacterDefining(c.getChangedCardColorsCharacterDefiningTable());

newCard.setChangedCardTypes(c.getChangedCardTypesTable());
newCard.setChangedCardTypesCharacterDefining(c.getChangedCardTypesCharacterDefiningTable());
newCard.setChangedCardKeywords(c.getChangedCardKeywords());
newCard.setChangedCardNames(c.getChangedCardNames());
newCard.copyFrom(c);

for (Table.Cell<Long, Long, List<String>> kw : c.getHiddenExtrinsicKeywordsTable().cellSet()) {
newCard.addHiddenExtrinsicKeywords(kw.getRowKey(), kw.getColumnKey(), kw.getValue());
Expand Down
55 changes: 15 additions & 40 deletions forge-game/src/main/java/forge/game/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -988,15 +988,6 @@ public void updateNameforView() {
currentState.getView().updateName(currentState);
}

public Table<Long, Long, CardChangedName> getChangedCardNames() {
return changedCardNames;
}

public void setChangedCardNames(Table<Long, Long, CardChangedName> changedCardNames) {
this.changedCardNames.clear();
this.changedCardNames.putAll(changedCardNames);
}

public void setGamePieceType(GamePieceType gamePieceType) {
this.gamePieceType = gamePieceType;
this.view.updateGamePieceType(this);
Expand Down Expand Up @@ -4163,13 +4154,6 @@ public Iterable<CardChangedType> getChangedCardTypes() {
));
}

public Table<Long, Long, CardChangedType> getChangedCardTypesTable() {
return Tables.unmodifiableTable(changedCardTypes);
}
public Table<Long, Long, CardChangedType> getChangedCardTypesCharacterDefiningTable() {
return Tables.unmodifiableTable(changedCardTypesCharacterDefining);
}

public boolean clearChangedCardTypes() {
boolean changed = false;

Expand Down Expand Up @@ -4227,12 +4211,6 @@ public Table<Long, Long, KeywordsChange> getChangedCardKeywords() {
return changedCardKeywords;
}

public Table<Long, Long, CardColor> getChangedCardColorsTable() {
return changedCardColors;
}
public Table<Long, Long, CardColor> getChangedCardColorsCharacterDefiningTable() {
return changedCardColorsCharacterDefining;
}
public Iterable<CardColor> getChangedCardColors() {
return Iterables.concat(changedCardColorsByText.values(), changedCardColorsCharacterDefining.values(), changedCardColors.values());
}
Expand Down Expand Up @@ -7754,31 +7732,13 @@ public List<KeywordInterface> getKeywords() {
}
}

public void setChangedCardTypes(Table<Long, Long, CardChangedType> changedCardTypes) {
this.changedCardTypes.clear();
this.changedCardTypes.putAll(changedCardTypes);
}
public void setChangedCardTypesCharacterDefining(Table<Long, Long, CardChangedType> changedCardTypes) {
this.changedCardTypesCharacterDefining.clear();
this.changedCardTypesCharacterDefining.putAll(changedCardTypes);
}

public void setChangedCardKeywords(Table<Long, Long, KeywordsChange> changedCardKeywords) {
this.changedCardKeywords.clear();
for (Table.Cell<Long, Long, KeywordsChange> entry : changedCardKeywords.cellSet()) {
this.changedCardKeywords.put(entry.getRowKey(), entry.getColumnKey(), entry.getValue().copy(this, true));
}
}

public void setChangedCardColors(Table<Long, Long, CardColor> changedCardColors) {
this.changedCardColors.clear();
this.changedCardColors.putAll(changedCardColors);
}
public void setChangedCardColorsCharacterDefining(Table<Long, Long, CardColor> changedCardColors) {
this.changedCardColorsCharacterDefining.clear();
this.changedCardColorsCharacterDefining.putAll(changedCardColors);
}

public void cleanupCopiedChangesFrom(Card c) {
for (StaticAbility stAb : c.getStaticAbilities()) {
this.removeChangedCardTypes(c.getLayerTimestamp(), stAb.getId(), false);
Expand Down Expand Up @@ -8253,4 +8213,19 @@ public SpellAbility getUnlockAbility(CardStateName state) {
}
return unlockAbilities.get(state);
}

public void copyFrom(Card in) {
// clean is not needed?
this.changedCardColors.putAll(in.changedCardColors);
this.changedCardColorsCharacterDefining.putAll(in.changedCardColorsCharacterDefining);

setChangedCardKeywords(in.getChangedCardKeywords());

this.changedCardTypes.putAll(in.changedCardTypes);
this.changedCardTypesCharacterDefining.putAll(in.changedCardTypesCharacterDefining);

this.changedCardNames.putAll(in.changedCardNames);
setChangedCardTraits(in.getChangedCardTraits());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,7 @@ public Card getLKICopy(Map<Integer, Card> cachedMap) {

newCopy.setUnearthed(copyFrom.isUnearthed());

newCopy.setChangedCardColors(copyFrom.getChangedCardColorsTable());
newCopy.setChangedCardColorsCharacterDefining(copyFrom.getChangedCardColorsCharacterDefiningTable());
newCopy.setChangedCardKeywords(copyFrom.getChangedCardKeywords());
newCopy.setChangedCardTypes(copyFrom.getChangedCardTypesTable());
newCopy.setChangedCardTypesCharacterDefining(copyFrom.getChangedCardTypesCharacterDefiningTable());
newCopy.setChangedCardNames(copyFrom.getChangedCardNames());
newCopy.setChangedCardTraits(copyFrom.getChangedCardTraits());
newCopy.copyFrom(copyFrom);

// for getReplacementList (run after setChangedCardKeywords for caching)
newCopy.setStoredKeywords(copyFrom.getStoredKeywords(), true);
Expand Down

0 comments on commit 8121d15

Please sign in to comment.