mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
add option to auto-play "put top card on stack until" hits (#5258)
* rename variables * implement feature * readd null check
This commit is contained in:
parent
a6b5abf271
commit
116397cdb3
4 changed files with 45 additions and 14 deletions
|
|
@ -74,6 +74,7 @@
|
|||
#include <QPainter>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionMatch>
|
||||
#include <QtConcurrent>
|
||||
|
||||
// milliseconds in between triggers of the move top cards until action
|
||||
static constexpr int MOVE_TOP_CARD_UNTIL_INTERVAL = 100;
|
||||
|
|
@ -1351,30 +1352,43 @@ void Player::actMoveTopCardsUntil()
|
|||
{
|
||||
stopMoveTopCardsUntil();
|
||||
|
||||
DlgMoveTopCardsUntil dlg(game, previousMovingCardsUntilExpr, previousMovingCardsUntilNumberOfHits);
|
||||
DlgMoveTopCardsUntil dlg(game, movingCardsUntilExpr, movingCardsUntilNumberOfHits, movingCardsUntilAutoPlay);
|
||||
if (!dlg.exec()) {
|
||||
return;
|
||||
}
|
||||
|
||||
previousMovingCardsUntilExpr = dlg.getExpr();
|
||||
previousMovingCardsUntilNumberOfHits = dlg.getNumberOfHits();
|
||||
movingCardsUntilExpr = dlg.getExpr();
|
||||
movingCardsUntilNumberOfHits = dlg.getNumberOfHits();
|
||||
movingCardsUntilAutoPlay = dlg.isAutoPlay();
|
||||
|
||||
if (zones.value("deck")->getCards().empty()) {
|
||||
stopMoveTopCardsUntil();
|
||||
} else {
|
||||
movingCardsUntilFilter = FilterString(previousMovingCardsUntilExpr);
|
||||
movingCardsUntilCounter = previousMovingCardsUntilNumberOfHits;
|
||||
movingCardsUntilFilter = FilterString(movingCardsUntilExpr);
|
||||
movingCardsUntilCounter = movingCardsUntilNumberOfHits;
|
||||
movingCardsUntil = true;
|
||||
actMoveTopCardToPlay();
|
||||
}
|
||||
}
|
||||
|
||||
void Player::moveOneCardUntil(const CardInfoPtr card)
|
||||
void Player::moveOneCardUntil(CardItem *card)
|
||||
{
|
||||
moveTopCardTimer->stop();
|
||||
if (zones.value("deck")->getCards().empty() || card.isNull()) {
|
||||
|
||||
const bool isMatch = card && movingCardsUntilFilter.check(card->getInfo());
|
||||
|
||||
if (isMatch && movingCardsUntilAutoPlay) {
|
||||
// Directly calling playCard will deadlock, since we are already in the middle of processing an event.
|
||||
// Use QTimer::singleShot to queue up the playCard on the event loop.
|
||||
QTimer::singleShot(0, this, [card, this] {
|
||||
bool cipt = card && card->getInfo() && card->getInfo()->getCipt();
|
||||
playCard(card, false, cipt);
|
||||
});
|
||||
}
|
||||
|
||||
if (zones.value("deck")->getCards().empty() || !card) {
|
||||
stopMoveTopCardsUntil();
|
||||
} else if (movingCardsUntilFilter.check(card)) {
|
||||
} else if (isMatch) {
|
||||
--movingCardsUntilCounter;
|
||||
if (movingCardsUntilCounter > 0) {
|
||||
moveTopCardTimer->start();
|
||||
|
|
@ -2278,7 +2292,7 @@ void Player::eventMoveCard(const Event_MoveCard &event, const GameEventContext &
|
|||
updateCardMenu(card);
|
||||
|
||||
if (movingCardsUntil && startZoneString == "deck" && targetZone->getName() == "stack") {
|
||||
moveOneCardUntil(card->getInfo());
|
||||
moveOneCardUntil(card);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue