mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 13:33:55 -07:00
refactor: Create forManagedComponents method
This commit is contained in:
parent
b7b7a385ea
commit
c8b6d7bf83
2 changed files with 11 additions and 9 deletions
|
|
@ -144,9 +144,7 @@ void PlayerMenu::setShortcutsActive()
|
|||
}
|
||||
|
||||
if (!player->getGame()->getGameMetaInfo()->started()) {
|
||||
for (auto *component : managedComponents) {
|
||||
component->setShortcutsInactive();
|
||||
}
|
||||
forManagedComponents([](auto *component) { component->setShortcutsInactive(); });
|
||||
|
||||
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
|
||||
while (counterIterator.hasNext()) {
|
||||
|
|
@ -159,9 +157,7 @@ void PlayerMenu::setShortcutsActive()
|
|||
return;
|
||||
}
|
||||
|
||||
for (auto *component : managedComponents) {
|
||||
component->setShortcutsActive();
|
||||
}
|
||||
forManagedComponents([](auto *component) { component->setShortcutsActive(); });
|
||||
|
||||
// Counters implement AbstractPlayerComponent but are iterated via Player::counters
|
||||
// (the authoritative source) rather than managedComponents to avoid a redundant
|
||||
|
|
@ -176,9 +172,7 @@ void PlayerMenu::setShortcutsInactive()
|
|||
{
|
||||
shortcutsActive = false;
|
||||
|
||||
for (auto *component : managedComponents) {
|
||||
component->setShortcutsInactive();
|
||||
}
|
||||
forManagedComponents([](auto *component) { component->setShortcutsInactive(); });
|
||||
|
||||
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
|
||||
while (counterIterator.hasNext()) {
|
||||
|
|
|
|||
|
|
@ -111,6 +111,14 @@ private:
|
|||
managedComponents.append(component);
|
||||
return component;
|
||||
}
|
||||
|
||||
/// Runs a normal for loop over all managedComponents, applying the provided function.
|
||||
template <typename Func> void forManagedComponents(Func func)
|
||||
{
|
||||
for (auto *component : managedComponents) {
|
||||
func(component);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_PLAYER_MENU_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue