mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 11:03:25 -08:00
[Refactor] Move card selection actions to GameScene and p/t parsing to CardState (#7426)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
c9853734ad
commit
4879ddbd0f
10 changed files with 121 additions and 116 deletions
|
|
@ -795,58 +795,6 @@ void PlayerActions::actMoveBottomCardToTop()
|
|||
sendGameCommand(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects all cards in the given zone.
|
||||
*
|
||||
* @param zone The zone to select from
|
||||
* @param filter A predicate to filter which cards are selected. Defaults to always returning true.
|
||||
*/
|
||||
static void selectCardsInZone(
|
||||
const CardZoneLogic *zone,
|
||||
std::function<bool(const CardItem *)> filter = [](const CardItem *) { return true; })
|
||||
{
|
||||
if (!zone) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &cardItem : zone->getCards()) {
|
||||
if (cardItem && filter(cardItem)) {
|
||||
cardItem->setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerActions::actSelectAll(const CardItem *card)
|
||||
{
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectCardsInZone(card->getZone());
|
||||
}
|
||||
|
||||
void PlayerActions::actSelectRow(const CardItem *card)
|
||||
{
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto isSameRow = [card](const CardItem *cardItem) {
|
||||
return qAbs(card->scenePos().y() - cardItem->scenePos().y()) < 50;
|
||||
};
|
||||
selectCardsInZone(card->getZone(), isSameRow);
|
||||
}
|
||||
|
||||
void PlayerActions::actSelectColumn(const CardItem *card)
|
||||
{
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto isSameColumn = [card](const CardItem *cardItem) { return cardItem->x() == card->x(); };
|
||||
selectCardsInZone(card->getZone(), isSameColumn);
|
||||
}
|
||||
|
||||
void PlayerActions::actDrawBottomCard()
|
||||
{
|
||||
if (player->getDeckZone()->getCards().empty()) {
|
||||
|
|
@ -1356,7 +1304,7 @@ void PlayerActions::actIncPT(QList<CardItem *> selectedCards, int deltaP, int de
|
|||
QList<const ::google::protobuf::Message *> commandList;
|
||||
for (auto card : selectedCards) {
|
||||
QString pt = card->getPT();
|
||||
const auto ptList = CardItem::parsePT(pt);
|
||||
const auto ptList = CardState::parsePT(pt);
|
||||
QString newpt;
|
||||
if (ptList.isEmpty()) {
|
||||
newpt = QString::number(deltaP) + (deltaT ? "/" + QString::number(deltaT) : "");
|
||||
|
|
@ -1432,7 +1380,7 @@ void PlayerActions::actSetPT(QList<CardItem *> selectedCards, const QString &pt)
|
|||
{
|
||||
int playerid = player->getPlayerInfo()->getId();
|
||||
|
||||
const auto ptList = CardItem::parsePT(pt);
|
||||
const auto ptList = CardState::parsePT(pt);
|
||||
bool empty = ptList.isEmpty();
|
||||
|
||||
QList<const ::google::protobuf::Message *> commandList;
|
||||
|
|
@ -1440,7 +1388,7 @@ void PlayerActions::actSetPT(QList<CardItem *> selectedCards, const QString &pt)
|
|||
auto *cmd = new Command_SetCardAttr;
|
||||
QString newpt = QString();
|
||||
if (!empty) {
|
||||
const auto oldpt = CardItem::parsePT(card->getPT());
|
||||
const auto oldpt = CardState::parsePT(card->getPT());
|
||||
int ptIter = 0;
|
||||
for (const auto &_item : ptList) {
|
||||
if (_item.typeId() == QMetaType::Type::Int) {
|
||||
|
|
@ -1537,7 +1485,7 @@ void PlayerActions::actReduceLifeByPower(QList<CardItem *> selectedCards)
|
|||
// calculate total power;
|
||||
int total = 0;
|
||||
for (auto card : selectedCards) {
|
||||
QVariantList parsed = CardItem::parsePT(card->getPT());
|
||||
QVariantList parsed = CardState::parsePT(card->getPT());
|
||||
if (!parsed.isEmpty()) {
|
||||
int power = parsed.first().toInt(); // toInt will default to 0 if it's not an int
|
||||
total += qMax(power, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue