mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-08 09:03:57 -07:00
refactor: extract tableRowToGridY helper on TableZone
Consolidates 5 duplicated callsites into a single helper that encapsulates the table-row-to-grid-Y mapping and the clamping of tableRow > 2 (instants/sorceries) to the noncreatures row. Resolves the TODO at createCard() requesting this extraction. Also fixes a latent bug where tableRow 3 mapped to the land row (gridY 0) instead of the noncreature row (gridY 1) at 4 callsites that lacked the > 2 guard.
This commit is contained in:
parent
8180d2e3b0
commit
0c8f4d403c
3 changed files with 20 additions and 12 deletions
|
|
@ -75,7 +75,7 @@ void PlayerActions::playCard(CardItem *card, bool faceDown)
|
||||||
cmd.set_y(0);
|
cmd.set_y(0);
|
||||||
} else {
|
} else {
|
||||||
tableRow = faceDown ? 2 : info.getUiAttributes().tableRow;
|
tableRow = faceDown ? 2 : info.getUiAttributes().tableRow;
|
||||||
QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - tableRow));
|
QPoint gridPoint = QPoint(-1, TableZone::tableRowToGridY(tableRow));
|
||||||
cardToMove->set_face_down(faceDown);
|
cardToMove->set_face_down(faceDown);
|
||||||
if (!faceDown) {
|
if (!faceDown) {
|
||||||
cardToMove->set_pt(info.getPowTough().toStdString());
|
cardToMove->set_pt(info.getPowTough().toStdString());
|
||||||
|
|
@ -114,12 +114,7 @@ void PlayerActions::playCardToTable(const CardItem *card, bool faceDown)
|
||||||
const CardInfo &info = exactCard.getInfo();
|
const CardInfo &info = exactCard.getInfo();
|
||||||
|
|
||||||
int tableRow = faceDown ? 2 : info.getUiAttributes().tableRow;
|
int tableRow = faceDown ? 2 : info.getUiAttributes().tableRow;
|
||||||
// default instant/sorcery cards to the noncreatures row
|
QPoint gridPoint = QPoint(-1, TableZone::tableRowToGridY(tableRow));
|
||||||
if (tableRow > 2) {
|
|
||||||
tableRow = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - tableRow));
|
|
||||||
cardToMove->set_face_down(faceDown);
|
cardToMove->set_face_down(faceDown);
|
||||||
if (!faceDown) {
|
if (!faceDown) {
|
||||||
cardToMove->set_pt(info.getPowTough().toStdString());
|
cardToMove->set_pt(info.getPowTough().toStdString());
|
||||||
|
|
@ -869,7 +864,7 @@ void PlayerActions::actCreateToken()
|
||||||
ExactCard correctedCard = CardDatabaseManager::query()->guessCard({lastTokenInfo.name, lastTokenInfo.providerId});
|
ExactCard correctedCard = CardDatabaseManager::query()->guessCard({lastTokenInfo.name, lastTokenInfo.providerId});
|
||||||
if (correctedCard) {
|
if (correctedCard) {
|
||||||
lastTokenInfo.name = correctedCard.getName();
|
lastTokenInfo.name = correctedCard.getName();
|
||||||
lastTokenTableRow = TableZone::clampValidTableRow(2 - correctedCard.getInfo().getUiAttributes().tableRow);
|
lastTokenTableRow = TableZone::tableRowToGridY(correctedCard.getInfo().getUiAttributes().tableRow);
|
||||||
if (lastTokenInfo.pt.isEmpty()) {
|
if (lastTokenInfo.pt.isEmpty()) {
|
||||||
lastTokenInfo.pt = correctedCard.getInfo().getPowTough();
|
lastTokenInfo.pt = correctedCard.getInfo().getPowTough();
|
||||||
}
|
}
|
||||||
|
|
@ -920,7 +915,7 @@ void PlayerActions::setLastToken(CardInfoPtr cardInfo)
|
||||||
.providerId =
|
.providerId =
|
||||||
SettingsCache::instance().cardOverrides().getCardPreferenceOverride(cardInfo->getName())};
|
SettingsCache::instance().cardOverrides().getCardPreferenceOverride(cardInfo->getName())};
|
||||||
|
|
||||||
lastTokenTableRow = TableZone::clampValidTableRow(2 - cardInfo->getUiAttributes().tableRow);
|
lastTokenTableRow = TableZone::tableRowToGridY(cardInfo->getUiAttributes().tableRow);
|
||||||
|
|
||||||
utilityMenu->setAndEnableCreateAnotherTokenAction(tr("C&reate another %1 token").arg(lastTokenInfo.name));
|
utilityMenu->setAndEnableCreateAnotherTokenAction(tr("C&reate another %1 token").arg(lastTokenInfo.name));
|
||||||
}
|
}
|
||||||
|
|
@ -1088,9 +1083,7 @@ void PlayerActions::createCard(const CardItem *sourceCard,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the target token's location
|
QPoint gridPoint = QPoint(-1, TableZone::tableRowToGridY(cardInfo->getUiAttributes().tableRow));
|
||||||
// TODO: Define this QPoint into its own function along with the one below
|
|
||||||
QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - cardInfo->getUiAttributes().tableRow));
|
|
||||||
|
|
||||||
// create the token for the related card
|
// create the token for the related card
|
||||||
Command_CreateToken cmd;
|
Command_CreateToken cmd;
|
||||||
|
|
|
||||||
|
|
@ -382,3 +382,11 @@ int TableZone::clampValidTableRow(const int row)
|
||||||
return TABLEROWS - 1;
|
return TABLEROWS - 1;
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TableZone::tableRowToGridY(int tableRow)
|
||||||
|
{
|
||||||
|
if (tableRow > 2) {
|
||||||
|
tableRow = 1;
|
||||||
|
}
|
||||||
|
return clampValidTableRow(2 - tableRow);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,13 @@ public:
|
||||||
|
|
||||||
static int clampValidTableRow(const int row);
|
static int clampValidTableRow(const int row);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a card's logical table row (0=creatures, 1=noncreatures, 2=lands)
|
||||||
|
* to the corresponding grid Y coordinate. Cards with tableRow > 2 (e.g.,
|
||||||
|
* instants/sorceries) default to the noncreatures row.
|
||||||
|
*/
|
||||||
|
static int tableRowToGridY(int tableRow);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Resizes the TableZone in case CardItems are within or
|
Resizes the TableZone in case CardItems are within or
|
||||||
outside of the TableZone constraints.
|
outside of the TableZone constraints.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue