mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-23 01:55:10 -07:00
Extract to function
Took 4 minutes
This commit is contained in:
parent
09260ee7d9
commit
7cfa78a055
2 changed files with 21 additions and 13 deletions
|
|
@ -209,18 +209,29 @@ InnerDecklistNode *DecklistNodeTree::getZoneObjFromName(const QString &zoneName)
|
||||||
return new InnerDecklistNode(zoneName, root);
|
return new InnerDecklistNode(zoneName, root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InnerDecklistNode *DecklistNodeTree::findBoardZone(const QString &boardZoneName) const
|
||||||
|
{
|
||||||
|
return dynamic_cast<InnerDecklistNode *>(root->findChild(boardZoneName));
|
||||||
|
}
|
||||||
|
|
||||||
|
InnerDecklistNode *DecklistNodeTree::findOrCreateBoardZone(const QString &boardZoneName)
|
||||||
|
{
|
||||||
|
auto *boardZone = findBoardZone(boardZoneName);
|
||||||
|
if (!boardZone &&
|
||||||
|
(boardZoneName == DECK_ZONE_MAYBEBOARD || boardZoneName == DECK_ZONE_MAIN || boardZoneName == DECK_ZONE_SIDE)) {
|
||||||
|
// The boards are lazy zones: they only exist once cards or custom zones need them.
|
||||||
|
boardZone = new InnerDecklistNode(boardZoneName, root);
|
||||||
|
}
|
||||||
|
return boardZone;
|
||||||
|
}
|
||||||
|
|
||||||
InnerDecklistNode *DecklistNodeTree::addCustomZone(const QString &boardZoneName, const QString &zoneName)
|
InnerDecklistNode *DecklistNodeTree::addCustomZone(const QString &boardZoneName, const QString &zoneName)
|
||||||
{
|
{
|
||||||
if (hasZoneName(zoneName)) {
|
if (hasZoneName(zoneName)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *boardZone = dynamic_cast<InnerDecklistNode *>(root->findChild(boardZoneName));
|
auto *boardZone = findOrCreateBoardZone(boardZoneName);
|
||||||
if (!boardZone &&
|
|
||||||
(boardZoneName == DECK_ZONE_MAYBEBOARD || boardZoneName == DECK_ZONE_MAIN || boardZoneName == DECK_ZONE_SIDE)) {
|
|
||||||
// The boards are lazy zones: they only exist once cards or custom zones need them.
|
|
||||||
boardZone = new InnerDecklistNode(boardZoneName, root);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!boardZone) {
|
if (!boardZone) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -256,12 +267,7 @@ bool DecklistNodeTree::moveCustomZone(const QString &zoneName, const QString &ne
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *newBoardZone = dynamic_cast<InnerDecklistNode *>(root->findChild(newBoardZoneName));
|
auto *newBoardZone = findOrCreateBoardZone(newBoardZoneName);
|
||||||
if (!newBoardZone && (newBoardZoneName == DECK_ZONE_MAYBEBOARD || newBoardZoneName == DECK_ZONE_MAIN ||
|
|
||||||
newBoardZoneName == DECK_ZONE_SIDE)) {
|
|
||||||
// The boards are lazy zones: they only exist once cards or custom zones need them.
|
|
||||||
newBoardZone = new InnerDecklistNode(newBoardZoneName, root);
|
|
||||||
}
|
|
||||||
if (!newBoardZone) {
|
if (!newBoardZone) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -290,7 +296,7 @@ QList<const InnerDecklistNode *> DecklistNodeTree::getCustomZones(const QString
|
||||||
{
|
{
|
||||||
QList<const InnerDecklistNode *> result;
|
QList<const InnerDecklistNode *> result;
|
||||||
|
|
||||||
auto *boardZone = dynamic_cast<InnerDecklistNode *>(root->findChild(boardZoneName));
|
auto *boardZone = findBoardZone(boardZoneName);
|
||||||
if (!boardZone) {
|
if (!boardZone) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,8 @@ public:
|
||||||
private:
|
private:
|
||||||
// Helpers for traversing the tree
|
// Helpers for traversing the tree
|
||||||
InnerDecklistNode *getZoneObjFromName(const QString &zoneName) const;
|
InnerDecklistNode *getZoneObjFromName(const QString &zoneName) const;
|
||||||
|
InnerDecklistNode *findBoardZone(const QString &boardZoneName) const;
|
||||||
|
InnerDecklistNode *findOrCreateBoardZone(const QString &boardZoneName);
|
||||||
InnerDecklistNode *findCustomZoneByName(const QString &zoneName) const;
|
InnerDecklistNode *findCustomZoneByName(const QString &zoneName) const;
|
||||||
bool hasZoneName(const QString &zoneName) const;
|
bool hasZoneName(const QString &zoneName) const;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue