Skip to content
Open
4 changes: 4 additions & 0 deletions forge-core/src/main/java/forge/deck/CardPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public int countByName(PaperCard card) {
return this.countAll((c) -> c.getName().equals(card.getName()));
}

public int countByNameAndEdition(PaperCard card) {
return this.countAll((c) -> c.getName().equals(card.getName()) && c.getEdition().equals(card.getEdition()));
}

/**
* Get the Map of frequencies (i.e. counts) for all the CardEdition found
* among cards in the Pool.
Expand Down
9 changes: 6 additions & 3 deletions forge-core/src/main/java/forge/item/PaperCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ public boolean equals(final Object obj) {
if (!name.equals(other.name)) {
return false;
}
if (!edition.equals(other.edition)) {
CardEdition thisCardEdition = StaticData.instance().getCardEdition(edition);
CardEdition otherCardEdition = StaticData.instance().getCardEdition(other.getEdition());
if (!thisCardEdition.equals(otherCardEdition)) {
return false;
}
if (!getCollectorNumber().equals(other.getCollectorNumber()))
Expand Down Expand Up @@ -415,8 +417,9 @@ public int compareTo(final IPaperCard o) {
if (0 != nameCmp) {
return nameCmp;
}
//FIXME: compare sets properly
int setDiff = edition.compareTo(o.getEdition());
CardEdition thisCardEdition = StaticData.instance().getCardEdition(edition);
CardEdition oCardEdition = StaticData.instance().getCardEdition(o.getEdition());
int setDiff = thisCardEdition.compareTo(oCardEdition);
if (0 != setDiff)
return setDiff;
String thisCollNrKey = getCollectorNumberSortingKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,11 @@ public void buildDeckMenu(FPopupMenu menu) {
super.buildDeckMenu(menu);
if (!(parentScreen instanceof AdventureDeckEditor adventureEditor) || adventureEditor.getAutoSellPage() == null)
return;
menu.addItem(new FMenuItem(Forge.getLocalizer().getMessage("btnCopyCollectionToClipboard"), Forge.hdbuttons ? FSkinImage.HDEXPORT : FSkinImage.BLANK, e1 -> FDeckViewer.copyCollectionToClipboard(AdventurePlayer.current().getCards())));

ItemPool<PaperCard> autoSellCards = AdventurePlayer.current().getAutoSellCards();
CardPool playedCards = AdventurePlayer.current().getCards().getFilteredPool(card -> !autoSellCards.contains(card));
menu.addItem(new FMenuItem(Forge.getLocalizer().getMessage("btnCopyCollectionToClipboard"), Forge.hdbuttons ? FSkinImage.HDEXPORT : FSkinImage.BLANK, e1 -> FDeckViewer.copyCollectionToClipboard(playedCards)));

Comment thread
Jetz72 marked this conversation as resolved.
Outdated
FMenuItem sellCurrentFilters = new FMenuItem(Forge.getLocalizer().getMessage("lblAutoSellCurrentFilters"), FSkinImage.QUEST_COINSTACK, e1 -> autoSellAllByFilter(adventureEditor.getAutoSellPage()));
sellCurrentFilters.setTextColor(255, 0, 0);
menu.addItem(sellCurrentFilters);
Expand Down
48 changes: 41 additions & 7 deletions forge-gui-mobile/src/forge/deck/FDeckViewer.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package forge.deck;

import java.util.Set;
import java.util.HashSet;
import java.util.Map;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.regex.Pattern;

import forge.Forge;
import forge.assets.FImage;
Expand Down Expand Up @@ -51,14 +55,44 @@ public static void copyDeckToClipboard(Deck deck) {
public static void copyCollectionToClipboard(CardPool pool) {
final String nl = System.lineSeparator();
final StringBuilder collectionList = new StringBuilder();
Set<String> accounted = new HashSet<>();
Map<String, String> accountedMap = new HashMap<>();
collectionList.append("\"Count\",\"Name\",\"Edition\"").append(nl);
Pattern regexQuote = Pattern.compile("\"");
Pattern regexA = Pattern.compile("[\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5]");
Pattern regexE = Pattern.compile("[\u00E8\u00E9\u00EA\u00EB]");
Pattern regexI = Pattern.compile("[\u00EC\u00ED\u00EE\u00EF]");
Pattern regexO = Pattern.compile("[\u00F2\u00F3\u00F4\u00F5\u00F6]");
Pattern regexU = Pattern.compile("[\u00F9\u00FA\u00FB\u00FC]");
Pattern regexEdPlst = Pattern.compile("PLIST|MB1");
Pattern regexEdNem = Pattern.compile("NMS");
Pattern regexEdP02 = Pattern.compile("PO2");

for (final Entry<PaperCard, Integer> entry : pool) {
String cardName = entry.getKey().getCardName();
if (!accounted.contains(cardName)) {
collectionList.append(pool.countByName(cardName)).append(" ").append(cardName).append(nl);
accounted.add(cardName);
PaperCard card = entry.getKey();
String cardName = card.getCardName();
String cardEdition = card.getEdition();
String accountedKey = cardName + '\t' + cardEdition;
if (!accountedMap.containsKey(accountedKey) && !card.isVeryBasicLand()) {
String regexCardName = regexQuote.matcher(cardName).replaceAll("\"\"");
regexCardName = regexA.matcher(regexCardName).replaceAll("a");
regexCardName = regexE.matcher(regexCardName).replaceAll("e");
regexCardName = regexI.matcher(regexCardName).replaceAll("i");
regexCardName = regexO.matcher(regexCardName).replaceAll("o");
regexCardName = regexU.matcher(regexCardName).replaceAll("u");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have StringUtils::stripAccents, but why wouldn't we want to export the oracle name?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Moxfield csv import can't handle accented characters so we need to replace them with the ASCII equivalents.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strikes me as something that'd ideally be fixed on their end, rather than making our end less correct and less consistent in order to have compatibility with an arbitrary platform. Have you tried reaching out to them?

String regexCardEdition = regexEdPlst.matcher(cardEdition).replaceAll("PLST");
regexCardEdition = regexEdNem.matcher(regexCardEdition).replaceAll("NEM");
regexCardEdition = regexEdP02.matcher(regexCardEdition).replaceAll("P02");
String cardLine = "\"" + pool.countByNameAndEdition(card) + "\",\"" + regexCardName + "\",\"" + regexCardEdition + "\"" + nl;
accountedMap.put(accountedKey, cardLine);
}
}

List<String> sortedKeys = new ArrayList<>(accountedMap.keySet());
Collections.sort(sortedKeys);
for (String key : sortedKeys) {
collectionList.append(accountedMap.get(key));
}

Forge.getClipboard().setContents(collectionList.toString());
FOptionPane.showMessageDialog(Forge.getLocalizer().getMessage("lblCollectionCopiedClipboard"));
}
Expand Down