mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 01:23:24 -08:00
Support tab-separated deck imports (#4222) (#7267)
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 cover (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 cover (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
Third-party deck tools (e.g. Delver Lens) export decks as tab-separated rows such as "2 Card Name Set Name". Card names never contain tab characters, so a leading numeric column marks a tabular record: the first two columns are read as the quantity and card name, and any further columns are discarded as printer/set metadata. - deck_list: parse tab-delimited rows before whitespace collapsing - tests: cover tab-separated mainboard and sideboard imports - docs: document the accepted plain-text import format (fills the TODO) Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
8968709642
commit
96b819d7c8
3 changed files with 60 additions and 7 deletions
|
|
@ -33,6 +33,7 @@ bool parse(QTextStream &in,
|
|||
|
||||
// Regex for advanced card parsing
|
||||
static const QRegularExpression reMultiplier(R"(^[xX\(\[]*(\d+)[xX\*\)\]]* ?(.+))");
|
||||
static const QRegularExpression reTabQuantity(R"(^\d+[xX]?$)");
|
||||
|
||||
// Regex for extracting set code and collector number with attached symbols
|
||||
static const QRegularExpression reHyphenFormat(R"(\((\w{3,})\)\s+(\w{3,})-(\d+[^\w\s]*))");
|
||||
|
|
@ -110,8 +111,34 @@ bool parse(QTextStream &in,
|
|||
continue;
|
||||
}
|
||||
|
||||
QString cardName = match.captured().simplified();
|
||||
const QString rawLine = match.captured();
|
||||
QString cardName = rawLine.simplified();
|
||||
bool sideboard = false;
|
||||
int amount = 1;
|
||||
|
||||
// Card names never contain tab characters, so a leading numeric field
|
||||
// marks a tabular record emitted by third-party deck tools (e.g. Delver
|
||||
// Lens "2\tCard Name\tSet Name"). The first two columns are the quantity
|
||||
// and the card name; any further columns are printer/set metadata and
|
||||
// are discarded.
|
||||
bool hasTabQuantity = false;
|
||||
const auto tabFields = rawLine.split('\t');
|
||||
int firstField = 0;
|
||||
while (firstField < tabFields.size() && tabFields.at(firstField).trimmed().isEmpty()) {
|
||||
++firstField;
|
||||
}
|
||||
if (firstField + 1 < tabFields.size()) {
|
||||
const QString quantity = tabFields.at(firstField).trimmed();
|
||||
if (reTabQuantity.match(quantity).hasMatch()) {
|
||||
hasTabQuantity = true;
|
||||
QString digits = quantity;
|
||||
if (digits.endsWith('x') || digits.endsWith('X')) {
|
||||
digits.chop(1);
|
||||
}
|
||||
amount = digits.toInt();
|
||||
cardName = tabFields.at(firstField + 1).simplified();
|
||||
}
|
||||
}
|
||||
|
||||
// Sideboard detection
|
||||
if (sBStart < 0) {
|
||||
|
|
@ -156,11 +183,12 @@ bool parse(QTextStream &in,
|
|||
}
|
||||
|
||||
// check if a specific amount is mentioned
|
||||
int amount = 1;
|
||||
match = reMultiplier.match(cardName);
|
||||
if (match.hasMatch()) {
|
||||
amount = match.captured(1).toInt();
|
||||
cardName = match.captured(2);
|
||||
if (!hasTabQuantity) {
|
||||
match = reMultiplier.match(cardName);
|
||||
if (match.hasMatch()) {
|
||||
amount = match.captured(1).toInt();
|
||||
cardName = match.captured(2);
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize the card name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue