diff options
Diffstat (limited to 'sigencore/plugins/PlayerPlugin.cpp')
-rw-r--r-- | sigencore/plugins/PlayerPlugin.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/sigencore/plugins/PlayerPlugin.cpp b/sigencore/plugins/PlayerPlugin.cpp new file mode 100644 index 00000000..d9f577a0 --- /dev/null +++ b/sigencore/plugins/PlayerPlugin.cpp @@ -0,0 +1,80 @@ +/* + * Copyright 2009 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "PlayerPlugin.h" +#include "PlayerPlugin_p.h" + +// Sigencore includes +#include <sigencore/Player.h> + +// Qt includes +#include <QtCore/QSignalMapper> + +using namespace Sigscript; +using namespace Sigencore; +using namespace Sigencore::Plugins; + +PlayerPlugin::PlayerPlugin(QObject* parent, const QVariantList& args) : + PluginBase(parent, args), + d(new Private(this, args)) +{ +} + +PlayerPlugin::~PlayerPlugin() +{ + delete d; +} + +Player* PlayerPlugin::getPlayer(const QString& name, GameWrapper* game, Config* parent) +{ + Player* player = createPlayer(name, game, parent); + if (player) + { + ++m_count; + d->addPlayer(player); + } + return player; +} + +PlayerPlugin::Private::Private(PlayerPlugin* plugin, const QVariantList& args) : + q(plugin), + m_mapper(new QSignalMapper(this)) +{ + Q_UNUSED(args) + connect(m_mapper, SIGNAL(mapped(QObject*)), this, SLOT(cleanupPlayer(QObject*))); +} + +PlayerPlugin::Private::~Private() +{ +} + +void PlayerPlugin::Private::addPlayer(Player* player) +{ + connect(player, SIGNAL(cleanupPlayer()), m_mapper, SLOT(map())); + m_mapper->setMapping(player, player); +} + +void PlayerPlugin::Private::cleanupPlayer(QObject* object) +{ + Player* player = qobject_cast<Player*>(object); + if (player) + { + q->cleanupPlayer(player); + --q->m_count; + } +} |