mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 08:22:15 -07:00
move thing out
This commit is contained in:
parent
c04e2a444b
commit
f9c0e2078c
4 changed files with 42 additions and 13 deletions
|
|
@ -15,6 +15,7 @@ set(oracle_SOURCES
|
||||||
src/oraclewizard.cpp
|
src/oraclewizard.cpp
|
||||||
src/oracleimporter.cpp
|
src/oracleimporter.cpp
|
||||||
src/pagetemplates.cpp
|
src/pagetemplates.cpp
|
||||||
|
src/parsehelpers.cpp
|
||||||
src/qt-json/json.cpp
|
src/qt-json/json.cpp
|
||||||
../cockatrice/src/game/cards/card_database.cpp
|
../cockatrice/src/game/cards/card_database.cpp
|
||||||
../cockatrice/src/game/cards/card_database_manager.cpp
|
../cockatrice/src/game/cards/card_database_manager.cpp
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "oracleimporter.h"
|
#include "oracleimporter.h"
|
||||||
|
|
||||||
#include "game/cards/card_database_parser/cockatrice_xml_4.h"
|
#include "game/cards/card_database_parser/cockatrice_xml_4.h"
|
||||||
|
#include "parsehelpers.h"
|
||||||
#include "qt-json/json.h"
|
#include "qt-json/json.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
@ -107,19 +108,6 @@ QString OracleImporter::getMainCardType(const QStringList &typeList)
|
||||||
return typeList.first();
|
return typeList.first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the card text to determine if the card enters the battlefield tapped.
|
|
||||||
*
|
|
||||||
* @param name The name of the card
|
|
||||||
* @param text The full oracle text of the card
|
|
||||||
*/
|
|
||||||
static bool parseCipt(const QString &name, const QString &text)
|
|
||||||
{
|
|
||||||
QRegularExpression ciptRegex("( it|" + QRegularExpression::escape(name) +
|
|
||||||
") enters( the battlefield)? tapped(?! unless)");
|
|
||||||
return ciptRegex.match(text).hasMatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
CardInfoPtr OracleImporter::addCard(QString name,
|
CardInfoPtr OracleImporter::addCard(QString name,
|
||||||
QString text,
|
QString text,
|
||||||
bool isToken,
|
bool isToken,
|
||||||
|
|
|
||||||
32
oracle/src/parsehelpers.cpp
Normal file
32
oracle/src/parsehelpers.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
#include "parsehelpers.h"
|
||||||
|
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the card text to determine if the card enters the battlefield tapped.
|
||||||
|
*
|
||||||
|
* The parsing logic will be able to handle the following cases:
|
||||||
|
* - "<name> enters tapped..."
|
||||||
|
* - shortname, if it appears at the start of the name.
|
||||||
|
* - "This <type> enters tapped..."
|
||||||
|
* - Any naming scheme that appends a non-alphanumeric character plus extra text to the end of the name.
|
||||||
|
* (e.g. name is "Card Name_SET" or "Card Name (Set)" and text contains "Card Name enters tapped...")
|
||||||
|
*
|
||||||
|
* However, it will still miss certain cases:
|
||||||
|
* - shortnames that aren't the first word in the card name
|
||||||
|
*
|
||||||
|
* @param name The name of the card
|
||||||
|
* @param text The oracle text of the card
|
||||||
|
*/
|
||||||
|
bool parseCipt(const QString &name, const QString &text)
|
||||||
|
{
|
||||||
|
static auto WHITESPACE_REGEX = QRegularExpression("\\s+");
|
||||||
|
QString shortname = name.split(WHITESPACE_REGEX, Qt::SkipEmptyParts).first();
|
||||||
|
|
||||||
|
QString namePattern = QString("( it|this [^ ]* |%1|%2.*)")
|
||||||
|
.arg(QRegularExpression::escape(name), QRegularExpression::escape(shortname));
|
||||||
|
|
||||||
|
QRegularExpression ciptRegex(namePattern + " enters( the battlefield)? tapped(?! unless)");
|
||||||
|
|
||||||
|
return ciptRegex.match(text).hasMatch();
|
||||||
|
}
|
||||||
8
oracle/src/parsehelpers.h
Normal file
8
oracle/src/parsehelpers.h
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef PARSEHELPERS_H
|
||||||
|
#define PARSEHELPERS_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
bool parseCipt(const QString &name, const QString &text);
|
||||||
|
|
||||||
|
#endif // PARSEHELPERS_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue