mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-22 06:43:54 -07:00
[Game] Refactor: move parsePT to a static method (#6860)
This commit is contained in:
parent
f223ff387e
commit
48e21aad38
4 changed files with 54 additions and 36 deletions
|
|
@ -1272,7 +1272,7 @@ void PlayerActions::actIncPT(int deltaP, int deltaT)
|
|||
for (const auto &item : player->getGameScene()->selectedItems()) {
|
||||
auto *card = static_cast<CardItem *>(item);
|
||||
QString pt = card->getPT();
|
||||
const auto ptList = parsePT(pt);
|
||||
const auto ptList = CardItem::parsePT(pt);
|
||||
QString newpt;
|
||||
if (ptList.isEmpty()) {
|
||||
newpt = QString::number(deltaP) + (deltaT ? "/" + QString::number(deltaT) : "");
|
||||
|
|
@ -1332,37 +1332,6 @@ void PlayerActions::actResetPT()
|
|||
}
|
||||
}
|
||||
|
||||
QVariantList PlayerActions::parsePT(const QString &pt)
|
||||
{
|
||||
QVariantList ptList = QVariantList();
|
||||
if (!pt.isEmpty()) {
|
||||
int sep = pt.indexOf('/');
|
||||
if (sep == 0) {
|
||||
ptList.append(QVariant(pt.mid(1))); // cut off starting '/' and take full string
|
||||
} else {
|
||||
int start = 0;
|
||||
for (;;) {
|
||||
QString item = pt.mid(start, sep - start);
|
||||
if (item.isEmpty()) {
|
||||
ptList.append(QVariant(QString()));
|
||||
} else if (item[0] == '+') {
|
||||
ptList.append(QVariant(item.mid(1).toInt())); // add as int
|
||||
} else if (item[0] == '-') {
|
||||
ptList.append(QVariant(item.toInt())); // add as int
|
||||
} else {
|
||||
ptList.append(QVariant(item)); // add as qstring
|
||||
}
|
||||
if (sep == -1) {
|
||||
break;
|
||||
}
|
||||
start = sep + 1;
|
||||
sep = pt.indexOf('/', start);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ptList;
|
||||
}
|
||||
|
||||
void PlayerActions::actSetPT()
|
||||
{
|
||||
QString oldPT;
|
||||
|
|
@ -1384,7 +1353,7 @@ void PlayerActions::actSetPT()
|
|||
return;
|
||||
}
|
||||
|
||||
const auto ptList = parsePT(pt);
|
||||
const auto ptList = CardItem::parsePT(pt);
|
||||
bool empty = ptList.isEmpty();
|
||||
|
||||
QList<const ::google::protobuf::Message *> commandList;
|
||||
|
|
@ -1393,7 +1362,7 @@ void PlayerActions::actSetPT()
|
|||
auto *cmd = new Command_SetCardAttr;
|
||||
QString newpt = QString();
|
||||
if (!empty) {
|
||||
const auto oldpt = parsePT(card->getPT());
|
||||
const auto oldpt = CardItem::parsePT(card->getPT());
|
||||
int ptIter = 0;
|
||||
for (const auto &_item : ptList) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue