File indexing completed on 2024-04-14 14:31:59

0001 // Copyright (c) 2003 Rob Kaper <cap@capsi.com>
0002 //
0003 // This library is free software; you can redistribute it and/or
0004 // modify it under the terms of the GNU Lesser General Public
0005 // License version 2.1 as published by the Free Software Foundation.
0006 //
0007 // This library is distributed in the hope that it will be useful,
0008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0010 // Lesser General Public License for more details.
0011 //
0012 // You should have received a copy of the GNU Lesser General Public License
0013 // along with this library; see the file COPYING.LIB.  If not, write to
0014 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0015 // Boston, MA 02110-1301, USA.
0016 
0017 
0018 
0019 #include "game.h"
0020 
0021 #include "configoption.h"
0022 
0023 Game::Game(int gameId)
0024     : QObject()
0025     , m_changed(false)
0026     , m_canBeJoined(false)
0027     , m_canBeWatched(false)
0028     , m_id(gameId)
0029     , m_players(0)
0030     , m_master(nullptr)
0031 {
0032 }
0033 
0034 Game::~Game()
0035 {
0036     qDeleteAll(m_configOptions);
0037 }
0038 
0039 int Game::id() const
0040 {
0041     return m_id;
0042 }
0043 
0044 void Game::setCanBeJoined(bool canBeJoined)
0045 {
0046     if (m_canBeJoined != canBeJoined)
0047     {
0048         m_canBeJoined = canBeJoined;
0049         m_changed = true;
0050     }
0051 }
0052 
0053 bool Game::canBeJoined() const
0054 {
0055     return m_canBeJoined;
0056 }
0057 
0058 void Game::setDescription(const QString &description)
0059 {
0060     if (m_description != description)
0061     {
0062         m_description = description;
0063         m_changed = true;
0064     }
0065 }
0066 
0067 QString Game::description() const
0068 {
0069     return m_description;
0070 }
0071 
0072 void Game::setName(const QString &name)
0073 {
0074     if (m_name != name)
0075     {
0076         m_name = name;
0077         m_changed = true;
0078     }
0079 }
0080 
0081 QString Game::name() const
0082 {
0083     return m_name;
0084 }
0085 
0086 void Game::setType(const QString &type)
0087 {
0088     if (m_type != type)
0089     {
0090         m_type = type;
0091         m_changed = true;
0092     }
0093 }
0094 
0095 QString Game::type() const
0096 {
0097     return m_type;
0098 }
0099 
0100 void Game::update(bool force)
0101 {
0102     if (m_changed || force)
0103     {
0104         Q_EMIT changed(this);
0105         m_changed = false;
0106     }
0107 }
0108 
0109 int Game::players() const
0110 {
0111     return m_players;
0112 }
0113 
0114 void Game::setPlayers(int players)
0115 {
0116     if (m_players != players)
0117     {
0118         m_players = players;
0119         m_changed = true;
0120     }
0121 }
0122 
0123 Player *Game::master() const
0124 {
0125     return m_master;
0126 }
0127 
0128 void Game::setMaster(Player *master)
0129 {
0130     if (m_master != master)
0131     {
0132         m_master = master;
0133         m_changed = true;
0134     }
0135 }
0136 
0137 void Game::setCanBeWatched(bool canBeWatched)
0138 {
0139     if (m_canBeWatched != canBeWatched)
0140     {
0141         m_canBeWatched = canBeWatched;
0142         m_changed = true;
0143     }
0144 }
0145 
0146 bool Game::canBeWatched() const
0147 {
0148     return m_canBeWatched;
0149 }
0150 
0151 QList<ConfigOption *> Game::configOptions() const
0152 {
0153     return m_configOptions;
0154 }
0155 
0156 void Game::addConfigOption(ConfigOption *configOption)
0157 {
0158     m_configOptions.append(configOption);
0159     Q_EMIT createGUI(configOption);
0160 }
0161 
0162 void Game::removeConfigOption(ConfigOption *configOption)
0163 {
0164     m_configOptions.removeOne(configOption);
0165     Q_EMIT removeGUI(configOption);
0166     configOption->deleteLater();
0167 }
0168 
0169 ConfigOption *Game::findConfigOption(int configId) const
0170 {
0171     foreach (ConfigOption *configOption, m_configOptions)
0172         if (configOption->id() == configId)
0173             return configOption;
0174 
0175     return nullptr;
0176 }
0177 
0178 ConfigOption *Game::findConfigOption(const QString &name) const
0179 {
0180     foreach (ConfigOption *configOption, m_configOptions)
0181         if (configOption->name() == name)
0182             return configOption;
0183 
0184     return nullptr;
0185 }
0186 
0187 #include "moc_game.cpp"