mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-10 04:16:43 -07:00
move CardNameNormalizer to libcockatrice_card
This commit is contained in:
parent
8ad366cdb8
commit
e594076338
11 changed files with 11 additions and 15 deletions
|
|
@ -7,12 +7,12 @@
|
|||
#ifndef INTERFACE_JSON_DECK_PARSER_H
|
||||
#define INTERFACE_JSON_DECK_PARSER_H
|
||||
|
||||
#include "../../../interface/deck_loader/card_name_normalizer.h"
|
||||
#include "../../../interface/deck_loader/card_node_function.h"
|
||||
#include "../../../interface/deck_loader/deck_loader.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <libcockatrice/card/import/card_name_normalizer.h>
|
||||
#include <libcockatrice/deck_list/deck_list.h>
|
||||
|
||||
class IJsonDeckParser
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
#include "card_name_normalizer.h"
|
||||
|
||||
#include "libcockatrice/card/database/card_database_manager.h"
|
||||
|
||||
QString CardNameNormalizer::operator()(const QString &cardNameString) const
|
||||
{
|
||||
QString cardName = cardNameString;
|
||||
|
||||
// Regex for advanced card parsing
|
||||
static const QRegularExpression reSplitCard(R"( ?\/\/ ?)");
|
||||
static const QRegularExpression reBrace(R"( ?[\[\{][^\]\}]*[\]\}] ?)"); // not nested
|
||||
static const QRegularExpression reRoundBrace(R"(^\([^\)]*\) ?)"); // () are only matched at start of string
|
||||
static const QRegularExpression reDigitBrace(R"( ?\(\d*\) ?)"); // () are matched if containing digits
|
||||
static const QRegularExpression reBraceDigit(
|
||||
R"( ?\([\dA-Z]+\) *\d+$)"); // () are matched if containing setcode then a number
|
||||
static const QRegularExpression reDoubleFacedMarker(R"( ?\(Transform\) ?)");
|
||||
|
||||
static const QHash<QRegularExpression, QString> differences{{QRegularExpression("’"), "'"},
|
||||
{QRegularExpression("Æ"), "Ae"},
|
||||
{QRegularExpression("æ"), "ae"},
|
||||
{QRegularExpression(" ?[|/]+ ?"), " // "}};
|
||||
|
||||
// Handle advanced card types
|
||||
if (cardName.contains(reSplitCard)) {
|
||||
cardName = cardName.split(reSplitCard).join(" // ");
|
||||
}
|
||||
|
||||
if (cardName.contains(reDoubleFacedMarker)) {
|
||||
QStringList faces = cardName.split(reDoubleFacedMarker);
|
||||
cardName = faces.first().trimmed();
|
||||
}
|
||||
|
||||
// Remove unnecessary characters
|
||||
cardName.remove(reBrace);
|
||||
cardName.remove(reRoundBrace); // I'll be entirely honest here, these are split to accommodate just three cards
|
||||
cardName.remove(reDigitBrace); // from un-sets that have a word in between round braces at the end
|
||||
cardName.remove(reBraceDigit); // very specific format with the set code in () and collectors number after
|
||||
|
||||
// Normalize characters
|
||||
for (auto diff = differences.constBegin(); diff != differences.constEnd(); ++diff) {
|
||||
cardName.replace(diff.key(), diff.value());
|
||||
}
|
||||
|
||||
return cardName;
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#ifndef COCKATRICE_CARD_NAME_NORMALIZER_H
|
||||
#define COCKATRICE_CARD_NAME_NORMALIZER_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
/**
|
||||
* Functor that normalizes the raw card name parsed during a plaintext deck import into the card name that Cockatrice
|
||||
* uses.
|
||||
*/
|
||||
struct CardNameNormalizer
|
||||
{
|
||||
QString operator()(const QString &cardNameString) const;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_CARD_NAME_NORMALIZER_H
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
#include "deck_loader.h"
|
||||
|
||||
#include "card_name_normalizer.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDebug>
|
||||
|
|
@ -19,6 +17,7 @@
|
|||
#include <QtConcurrentRun>
|
||||
#include <libcockatrice/card/database/card_database.h>
|
||||
#include <libcockatrice/card/database/card_database_manager.h>
|
||||
#include <libcockatrice/card/import/card_name_normalizer.h>
|
||||
#include <libcockatrice/deck_list/deck_list.h>
|
||||
#include <libcockatrice/deck_list/tree/deck_list_card_node.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "dlg_load_deck_from_clipboard.h"
|
||||
|
||||
#include "../../../client/settings/cache_settings.h"
|
||||
#include "../../deck_loader/card_name_normalizer.h"
|
||||
#include "../../deck_loader/card_node_function.h"
|
||||
#include "../../deck_loader/deck_loader.h"
|
||||
#include "dlg_settings.h"
|
||||
|
|
@ -15,6 +14,7 @@
|
|||
#include <QPushButton>
|
||||
#include <QTextStream>
|
||||
#include <QVBoxLayout>
|
||||
#include <libcockatrice/card/import/card_name_normalizer.h>
|
||||
|
||||
/**
|
||||
* Creates the main layout and connects the signals that are common to all versions of this window
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#include "dlg_load_deck_from_website.h"
|
||||
|
||||
#include "../../deck_loader/card_name_normalizer.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDialogButtonBox>
|
||||
|
|
@ -10,6 +8,7 @@
|
|||
#include <QJsonObject>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkReply>
|
||||
#include <libcockatrice/card/import/card_name_normalizer.h>
|
||||
#include <version_string.h>
|
||||
|
||||
DlgLoadDeckFromWebsite::DlgLoadDeckFromWebsite(QWidget *parent) : QDialog(parent)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include <QDialog>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QLoggingCategory>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
#include "archidekt_api_response_deck_display_widget.h"
|
||||
|
||||
#include "../../../../../deck_loader/card_name_normalizer.h"
|
||||
#include "../../../../../deck_loader/card_node_function.h"
|
||||
#include "../../../../../deck_loader/deck_loader.h"
|
||||
#include "../../../../cards/card_info_picture_with_text_overlay_widget.h"
|
||||
#include "../../../../cards/card_size_widget.h"
|
||||
#include "../../../../cards/deck_card_zone_display_widget.h"
|
||||
#include "../../../../visual_deck_editor/visual_deck_display_options_widget.h"
|
||||
|
|
@ -11,7 +9,7 @@
|
|||
#include "../api_response/deck/archidekt_api_response_deck.h"
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <libcockatrice/card/database/card_database_manager.h>
|
||||
#include <libcockatrice/card/import/card_name_normalizer.h>
|
||||
|
||||
ArchidektApiResponseDeckDisplayWidget::ArchidektApiResponseDeckDisplayWidget(QWidget *parent,
|
||||
ArchidektApiResponseDeck _response,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
#include "edhrec_deck_api_response.h"
|
||||
|
||||
#include "../../../../../../deck_loader/card_name_normalizer.h"
|
||||
#include "../../../../../../deck_loader/deck_loader.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <libcockatrice/card/import/card_name_normalizer.h>
|
||||
|
||||
void EdhrecDeckApiResponse::fromJson(const QJsonArray &json)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue