mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-23 10:52:16 -07:00
clean up CardList::findCard
This commit is contained in:
parent
bb8c37b615
commit
b1911d13c8
2 changed files with 18 additions and 13 deletions
|
|
@ -9,21 +9,26 @@ CardList::CardList(bool _contentsKnown) : QList<CardItem *>(), contentsKnown(_co
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CardItem *CardList::findCard(const int id) const
|
/**
|
||||||
|
* @brief Finds the CardItem with the given id in the list.
|
||||||
|
* If contentsKnown is false, then this just returns the first element of the list.
|
||||||
|
*
|
||||||
|
* @param cardId The id of the card to find.
|
||||||
|
*
|
||||||
|
* @returns A pointer to the CardItem, or a nullptr if not found.
|
||||||
|
*/
|
||||||
|
CardItem *CardList::findCard(const int cardId) const
|
||||||
{
|
{
|
||||||
if (!contentsKnown) {
|
if (!contentsKnown && !empty()) {
|
||||||
if (empty())
|
return at(0);
|
||||||
return 0;
|
} else {
|
||||||
CardItem *temp = at(0);
|
for (auto *cardItem : *this) {
|
||||||
return temp;
|
if (cardItem->getId() == cardId) {
|
||||||
} else
|
return cardItem;
|
||||||
for (int i = 0; i < size(); i++) {
|
|
||||||
CardItem *temp = at(i);
|
|
||||||
if (temp->getId() == id) {
|
|
||||||
return temp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CardList::compareFunctor
|
class CardList::compareFunctor
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ public:
|
||||||
SortByType = 2
|
SortByType = 2
|
||||||
};
|
};
|
||||||
CardList(bool _contentsKnown);
|
CardList(bool _contentsKnown);
|
||||||
CardItem *findCard(const int id) const;
|
CardItem *findCard(const int cardId) const;
|
||||||
bool getContentsKnown() const
|
bool getContentsKnown() const
|
||||||
{
|
{
|
||||||
return contentsKnown;
|
return contentsKnown;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue