-
Notifications
You must be signed in to change notification settings - Fork 973
Updated 'Copy Collection to Clipboard' menu item in the inventory view #10925
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
60416e1
1bc96b1
a172a5f
f7752ca
4629267
848cc24
e5f0f2f
0e3788f
1745b02
d4fa614
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
|
|
@@ -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"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do have
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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")); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.