mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00:00
Clipboard .mtga deck importing & fixes to .mtga and .dck importers (#9321)
This commit is contained in:
parent
4728bac28e
commit
17deba2df3
4 changed files with 46 additions and 22 deletions
|
@ -68,7 +68,14 @@ public class DeckImportClipboardDialog extends MageDialog {
|
|||
}
|
||||
|
||||
private void onOK() {
|
||||
tmpPath = DeckUtil.writeTextToTempFile(editData.getText());
|
||||
String decklist = editData.getText();
|
||||
decklist = decklist.replace(FORMAT_TEXT, "");
|
||||
// This dialog also accepts a paste in .mtga format
|
||||
if (decklist.startsWith("Deck\n")) { // An .mtga list always starts with the first line being "Deck". This kind of paste is processed as .mtga
|
||||
tmpPath = DeckUtil.writeTextToTempFile("cbimportdeck", ".mtga", decklist);
|
||||
} else { // If the paste is not .mtga format, it's processed as plaintext
|
||||
tmpPath = DeckUtil.writeTextToTempFile(decklist);
|
||||
}
|
||||
this.removeDialog();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ public class CardNameUtil {
|
|||
.replace("à", "a")
|
||||
.replace("é", "e")
|
||||
.replace("ú", "u")
|
||||
.replace("\"", "'");
|
||||
.replace("†", "+");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package mage.cards.decks.importer;
|
||||
|
||||
import mage.cards.decks.CardNameUtil;
|
||||
import mage.cards.decks.DeckCardInfo;
|
||||
import mage.cards.decks.DeckCardLayout;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
@ -38,6 +39,8 @@ public class DckDeckImporter extends PlainTextDeckImporter {
|
|||
if (line.isEmpty() || line.startsWith("#")) {
|
||||
return;
|
||||
}
|
||||
|
||||
line = CardNameUtil.normalizeCardName(line);
|
||||
|
||||
// AUTO-FIX apply (if card number was fixed before then it can be replaced in layout or other lines too)
|
||||
for (Map.Entry<String, String> fix : this.possibleFixes.entrySet()) {
|
||||
|
|
|
@ -22,38 +22,52 @@ public class MtgaImporter extends PlainTextDeckImporter {
|
|||
"(\\p{Digit}+)" +
|
||||
"\\p{javaWhitespace}+" +
|
||||
"(" + CARD_NAME_PATTERN.pattern() + ")" +
|
||||
"\\p{javaWhitespace}+" +
|
||||
"\\((\\p{Alnum}+)\\)" +
|
||||
"\\p{javaWhitespace}+" +
|
||||
"(\\p{Digit}+)");
|
||||
"(?:\\p{javaWhitespace}+\\()?" +
|
||||
"(\\p{Alnum}+)?" +
|
||||
"(?:\\)\\p{javaWhitespace}+)?" +
|
||||
"(\\p{Graph}+)?");
|
||||
|
||||
private final CardLookup lookup = getCardLookup();
|
||||
private boolean sideboard = false;
|
||||
|
||||
@Override
|
||||
protected void readLine(String line, DeckCardLists deckList, FixedInfo fixedInfo) {
|
||||
|
||||
line = line.trim();
|
||||
|
||||
if (line.equals("Deck")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (line.trim().equals("")) {
|
||||
if (line.equals("Sideboard") || line.equals("")) {
|
||||
sideboard = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Matcher m = MTGA_PATTERN.matcher(CardNameUtil.normalizeCardName(line));
|
||||
if (m.matches()) {
|
||||
int count = Integer.parseInt(m.group(1));
|
||||
String name = m.group(2);
|
||||
String set = SET_REMAPPING.getOrDefault(m.group(3), m.group(3));
|
||||
String cardNumber = m.group(4);
|
||||
final List<DeckCardInfo> zone = sideboard ? deckList.getSideboard() : deckList.getCards();
|
||||
Optional<CardInfo> found = lookup.lookupCardInfo(name, set, cardNumber);
|
||||
if (!found.isPresent()) {
|
||||
sbMessage.append("Cound not find card for '").append(line).append("'\n");
|
||||
} else {
|
||||
found.ifPresent(card -> zone.addAll(Collections.nCopies(count,
|
||||
new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()))));
|
||||
}
|
||||
} else {
|
||||
Matcher pattern = MTGA_PATTERN.matcher(CardNameUtil.normalizeCardName(line));
|
||||
|
||||
if (!pattern.matches()) {
|
||||
sbMessage.append("Error reading '").append(line).append("'\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<CardInfo> found;
|
||||
int count = Integer.parseInt(pattern.group(1));
|
||||
String name = pattern.group(2);
|
||||
if (pattern.group(3) != null && pattern.group(4) != null) {
|
||||
String set = SET_REMAPPING.getOrDefault(pattern.group(3), pattern.group(3));
|
||||
String cardNumber = pattern.group(4);
|
||||
found = lookup.lookupCardInfo(name, set, cardNumber);
|
||||
} else {
|
||||
found = lookup.lookupCardInfo(name);
|
||||
}
|
||||
|
||||
if (!found.isPresent()) {
|
||||
sbMessage.append("Cound not find card for '").append(line).append("'\n");
|
||||
} else {
|
||||
final List<DeckCardInfo> zone = sideboard ? deckList.getSideboard() : deckList.getCards();
|
||||
found.ifPresent(card -> zone.addAll(Collections.nCopies(count,
|
||||
new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue