From 2a9aed653073becb61a8f364c9d72b56ec49e4eb Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 9 Apr 2009 16:09:24 -0400 Subject: Move plugins to subdirectories --- plugins/CMakeLists.txt | 7 +- plugins/arena/CMakeLists.txt | 3 + plugins/arena/standard/CMakeLists.txt | 40 ++++++ plugins/arena/standard/SigenArenas.cpp | 92 ++++++++++++ plugins/arena/standard/SigenArenas.h | 41 ++++++ plugins/arena/standard/atb/ATBArena.cpp | 90 ++++++++++++ plugins/arena/standard/atb/ATBArena.h | 59 ++++++++ plugins/arena/standard/atb/ATBTimer.cpp | 103 +++++++++++++ plugins/arena/standard/atb/ATBTimer.h | 58 ++++++++ plugins/arena/standard/atb/ActionMap.cpp | 55 +++++++ plugins/arena/standard/atb/ActionMap.h | 44 ++++++ plugins/arena/standard/sigen_arenas.desktop | 16 +++ plugins/arena/standard/standard/TurnArena.cpp | 160 +++++++++++++++++++++ plugins/arena/standard/standard/TurnArena.h | 60 ++++++++ plugins/canvas/CMakeLists.txt | 3 + plugins/canvas/standard/CMakeLists.txt | 38 +++++ plugins/canvas/standard/SigenCanvases.cpp | 79 ++++++++++ plugins/canvas/standard/SigenCanvases.h | 41 ++++++ .../canvas/standard/qgraphicsscene/QGSCanvas.cpp | 112 +++++++++++++++ plugins/canvas/standard/qgraphicsscene/QGSCanvas.h | 62 ++++++++ plugins/canvas/standard/sigen_canvases.desktop | 16 +++ plugins/sigen_arena_standard/CMakeLists.txt | 40 ------ plugins/sigen_arena_standard/SigenArenas.cpp | 92 ------------ plugins/sigen_arena_standard/SigenArenas.h | 41 ------ plugins/sigen_arena_standard/atb/ATBArena.cpp | 90 ------------ plugins/sigen_arena_standard/atb/ATBArena.h | 59 -------- plugins/sigen_arena_standard/atb/ATBTimer.cpp | 103 ------------- plugins/sigen_arena_standard/atb/ATBTimer.h | 58 -------- plugins/sigen_arena_standard/atb/ActionMap.cpp | 55 ------- plugins/sigen_arena_standard/atb/ActionMap.h | 44 ------ plugins/sigen_arena_standard/sigen_arenas.desktop | 16 --- .../sigen_arena_standard/standard/TurnArena.cpp | 160 --------------------- plugins/sigen_arena_standard/standard/TurnArena.h | 60 -------- plugins/sigen_canvas_standard/CMakeLists.txt | 38 ----- plugins/sigen_canvas_standard/SigenCanvases.cpp | 79 ---------- plugins/sigen_canvas_standard/SigenCanvases.h | 41 ------ .../qgraphicsscene/QGSCanvas.cpp | 112 --------------- .../qgraphicsscene/QGSCanvas.h | 62 -------- .../sigen_canvas_standard/sigen_canvases.desktop | 16 --- 39 files changed, 1174 insertions(+), 1171 deletions(-) create mode 100644 plugins/arena/CMakeLists.txt create mode 100644 plugins/arena/standard/CMakeLists.txt create mode 100644 plugins/arena/standard/SigenArenas.cpp create mode 100644 plugins/arena/standard/SigenArenas.h create mode 100644 plugins/arena/standard/atb/ATBArena.cpp create mode 100644 plugins/arena/standard/atb/ATBArena.h create mode 100644 plugins/arena/standard/atb/ATBTimer.cpp create mode 100644 plugins/arena/standard/atb/ATBTimer.h create mode 100644 plugins/arena/standard/atb/ActionMap.cpp create mode 100644 plugins/arena/standard/atb/ActionMap.h create mode 100644 plugins/arena/standard/sigen_arenas.desktop create mode 100644 plugins/arena/standard/standard/TurnArena.cpp create mode 100644 plugins/arena/standard/standard/TurnArena.h create mode 100644 plugins/canvas/CMakeLists.txt create mode 100644 plugins/canvas/standard/CMakeLists.txt create mode 100644 plugins/canvas/standard/SigenCanvases.cpp create mode 100644 plugins/canvas/standard/SigenCanvases.h create mode 100644 plugins/canvas/standard/qgraphicsscene/QGSCanvas.cpp create mode 100644 plugins/canvas/standard/qgraphicsscene/QGSCanvas.h create mode 100644 plugins/canvas/standard/sigen_canvases.desktop delete mode 100644 plugins/sigen_arena_standard/CMakeLists.txt delete mode 100644 plugins/sigen_arena_standard/SigenArenas.cpp delete mode 100644 plugins/sigen_arena_standard/SigenArenas.h delete mode 100644 plugins/sigen_arena_standard/atb/ATBArena.cpp delete mode 100644 plugins/sigen_arena_standard/atb/ATBArena.h delete mode 100644 plugins/sigen_arena_standard/atb/ATBTimer.cpp delete mode 100644 plugins/sigen_arena_standard/atb/ATBTimer.h delete mode 100644 plugins/sigen_arena_standard/atb/ActionMap.cpp delete mode 100644 plugins/sigen_arena_standard/atb/ActionMap.h delete mode 100644 plugins/sigen_arena_standard/sigen_arenas.desktop delete mode 100644 plugins/sigen_arena_standard/standard/TurnArena.cpp delete mode 100644 plugins/sigen_arena_standard/standard/TurnArena.h delete mode 100644 plugins/sigen_canvas_standard/CMakeLists.txt delete mode 100644 plugins/sigen_canvas_standard/SigenCanvases.cpp delete mode 100644 plugins/sigen_canvas_standard/SigenCanvases.h delete mode 100644 plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.cpp delete mode 100644 plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.h delete mode 100644 plugins/sigen_canvas_standard/sigen_canvases.desktop diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 7c2279d0..4febca48 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -1,7 +1,4 @@ project(plugins) -# Arena plugins -add_subdirectory(sigen_arena_standard) - -# Canvas plugins -add_subdirectory(sigen_canvas_standard) +add_subdirectory(arena) +add_subdirectory(canvas) diff --git a/plugins/arena/CMakeLists.txt b/plugins/arena/CMakeLists.txt new file mode 100644 index 00000000..a0b57536 --- /dev/null +++ b/plugins/arena/CMakeLists.txt @@ -0,0 +1,3 @@ +project(plugins) + +add_subdirectory(standard) diff --git a/plugins/arena/standard/CMakeLists.txt b/plugins/arena/standard/CMakeLists.txt new file mode 100644 index 00000000..de972424 --- /dev/null +++ b/plugins/arena/standard/CMakeLists.txt @@ -0,0 +1,40 @@ +project(sigenarenas) + +set(sigenarenas_SRCS + SigenArenas.cpp + atb/ActionMap.cpp + atb/ATBArena.cpp + atb/ATBTimer.cpp + standard/TurnArena.cpp +) +set(sigenarenas_SERVICES + sigen_arenas.desktop +) + +kde4_add_plugin(arena_sigen + ${sigenarenas_SRCS} +) +target_link_libraries(arena_sigen + ${QT_QTCORE_LIBRARY} + ${KDE4_KDEUI_LIBRARY} + ${KDE4_KROSSCORE_LIBRARY} + sigencoreplugins +) + +install( + TARGETS + arena_sigen + DESTINATION + ${PLUGIN_INSTALL_DIR} + COMPONENT + plugins +) + +install( + FILES + ${sigenarenas_SERVICES} + DESTINATION + ${SERVICES_INSTALL_DIR} + COMPONENT + plugins +) diff --git a/plugins/arena/standard/SigenArenas.cpp b/plugins/arena/standard/SigenArenas.cpp new file mode 100644 index 00000000..faf3f848 --- /dev/null +++ b/plugins/arena/standard/SigenArenas.cpp @@ -0,0 +1,92 @@ +/* + * Copyright 2009 Ben Boeckel + * + * 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 . + */ + +// Header include +#include "SigenArenas.h" + +// Arena includes +#include "standard/TurnArena.h" +#include "atb/ATBArena.h" + +// Sigencore includes +#include + +// KDE includes +#include + +SIGEN_ARENA_PLUGIN_VERSION(SigenArenas, "sigen_arenas", 000101) + +using namespace Sigscript; +using namespace Sigencore; +using namespace Sigencore::Plugins; + +SigenArenas::SigenArenas(QObject* parent, const QVariantList& args) : + ArenaPlugin(parent, args) +{ +} + +SigenArenas::~SigenArenas() +{ +} + +QStringList SigenArenas::classList() const +{ + return QStringList() << TurnArena::name() << ATBArena::name(); +} + +QString SigenArenas::description(const QString& name) const +{ + if (name == TurnArena::name()) + return TurnArena::description(); + if (name == ATBArena::name()) + return ATBArena::description(); + return "(Unknown arena)"; +} + +QIcon SigenArenas::icon(const QString& name) +{ + if (name == TurnArena::name()) + return TurnArena::icon(); + if (name == ATBArena::name()) + return ATBArena::icon(); + return KIcon(); +} + +Arena* SigenArenas::createArena(const QString& name, GameWrapper* game, Config* parent) +{ + if (name == TurnArena::name()) + return new TurnArena(game, parent); + if (name == ATBArena::name()) + return new ATBArena(game, parent); + return NULL; +} + +void SigenArenas::cleanupArena(Arena* arena) +{ + TurnArena* turnArena = qobject_cast(arena); + if (turnArena) + { + delete turnArena; + return; + } + ATBArena* atbArena = qobject_cast(arena); + if (atbArena) + { + delete atbArena; + return; + } +} diff --git a/plugins/arena/standard/SigenArenas.h b/plugins/arena/standard/SigenArenas.h new file mode 100644 index 00000000..14ce15c8 --- /dev/null +++ b/plugins/arena/standard/SigenArenas.h @@ -0,0 +1,41 @@ +/* + * Copyright 2009 Ben Boeckel + * + * 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 . + */ + +#ifndef SIGENARENAS_SIGENARENAS +#define SIGENARENAS_SIGENARENAS + +// Sigencore plugin includes +#include + +class SigenArenas : public Sigencore::Plugins::ArenaPlugin +{ + Q_OBJECT + + public: + SigenArenas(QObject* parent, const QVariantList& args); + ~SigenArenas(); + + QStringList classList() const; + QString description(const QString& name) const; + QIcon icon(const QString& name); + protected: + Sigencore::Arena* createArena(const QString& name, Sigscript::GameWrapper* game, Sigscript::Config* parent); + protected slots: + void cleanupArena(Sigencore::Arena* arena); +}; + +#endif diff --git a/plugins/arena/standard/atb/ATBArena.cpp b/plugins/arena/standard/atb/ATBArena.cpp new file mode 100644 index 00000000..21fd1914 --- /dev/null +++ b/plugins/arena/standard/atb/ATBArena.cpp @@ -0,0 +1,90 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 . + */ + +// Header includes +#include "ATBArena.h" + +// Sigbattle includes +#include "ATBTimer.h" + +// KDE includes +#include + +// Qt includes +#include +#include + +using namespace Sigscript; +using namespace Sigencore; + +ATBArena::ATBArena(GameWrapper* sigmod, Config* parent) : + Arena(sigmod, parent), + m_atbTimer(new ATBTimer(this, m_decisions)) +{ + connect(m_atbTimer, SIGNAL(actionReady(Sigencore::TeamMember*)), this, SLOT(processAction(Sigencore::TeamMember*))); + setupBattle(); +} + +ATBArena::~ATBArena() +{ +} + +QString ATBArena::name() +{ + return "Sigen ATB Arena"; +} + +QString ATBArena::description() +{ + return "An arena where creatures have an action bar which when filled, can act"; +} + +QIcon ATBArena::icon() +{ + // TODO + return KIcon(); +} + +void ATBArena::handleAction(TeamMember* teamMember, TeamMember::Action action) +{ + if ((action.first == TeamMember::Invalid) || (action.first == TeamMember::Timeout)) + return; + Arena::handleAction(teamMember, action); +} + +bool ATBArena::isTeamAllowed(Sigencore::Team* team) +{ + Q_UNUSED(team) + // TODO: Use rules format here? + return true; +} + +void ATBArena::setupBattle() +{ + Arena::setupBattle(); +} + +void ATBArena::processAction(TeamMember* teamMember) +{ + handleAction(teamMember, m_decisions[teamMember].second); + m_decisions.remove(teamMember); +} + +void ATBArena::cleanUp() +{ + Arena::cleanUp(); +} diff --git a/plugins/arena/standard/atb/ATBArena.h b/plugins/arena/standard/atb/ATBArena.h new file mode 100644 index 00000000..7e6e5b08 --- /dev/null +++ b/plugins/arena/standard/atb/ATBArena.h @@ -0,0 +1,59 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 . + */ + +#ifndef SIGENARENAS_ATBARENA +#define SIGENARENAS_ATBARENA + +// ATB includes +#include "ActionMap.h" + +// Sigencore includes +#include + +// Forward declaraions +class QTimer; +class ATBTimer; + +class ATBArena : public Sigencore::Arena +{ + Q_OBJECT + + public: + ATBArena(Sigscript::GameWrapper* game, Sigscript::Config* parent); + ~ATBArena(); + + static QString name(); + static QString description(); + static QIcon icon(); + protected: + virtual void handleAction(Sigencore::TeamMember* teamMember, Sigencore::TeamMember::Action action); + + virtual bool isTeamAllowed(Sigencore::Team* team); + + virtual void setupBattle(); + + Kross::ActionCollection* m_priorityScripts; + protected slots: + void processAction(Sigencore::TeamMember* teamMember); + + virtual void cleanUp(); + private: + ActionMap m_decisions; + ATBTimer* m_atbTimer; +}; + +#endif diff --git a/plugins/arena/standard/atb/ATBTimer.cpp b/plugins/arena/standard/atb/ATBTimer.cpp new file mode 100644 index 00000000..adb2a853 --- /dev/null +++ b/plugins/arena/standard/atb/ATBTimer.cpp @@ -0,0 +1,103 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 . + */ + +// Header include +#include "ATBTimer.h" + +// ATB includes +#include "ActionMap.h" +#include "ATBArena.h" + +// Sigscript includes +#include +#include + +// Qt includes +#include +#include +#include +#include + +using namespace Sigencore; + +struct ATBTimer::TimerIncrementFunctor +{ + TimerIncrementFunctor(ATBTimer* timer) : + m_timer(timer) + { + } + + typedef bool result_type; + + bool operator()(TeamMember* teamMember) + { + double factor = .1; + m_timer->m_arena->valueOfType("meter-factor", &factor); + if (!m_timer->m_actions.contains(teamMember)) + { + m_timer->m_timers[teamMember] += teamMember->statValue(Sigmod::ST_Speed) * factor; + int threshold = 1000; + m_timer->m_arena->valueOfType("meter-threshold", &threshold); + if (threshold <= m_timer->m_timers[teamMember]) + { + QFutureWatcher* watcher = new QFutureWatcher(m_timer); + TeamMember::RequestedAction action = requestDecision(teamMember); + watcher->setFuture(action.second); + m_timer->connect(watcher, SIGNAL(finished()), m_timer->m_actionMapper, SLOT(map())); + m_timer->connect(watcher, SIGNAL(finished()), SLOT(deleteLater())); + m_timer->m_actionMapper->setMapping(watcher, teamMember); + m_timer->m_actions.set(teamMember, action); + } + } + return false; + } + + ATBTimer* m_timer; +}; + +ATBTimer::ATBTimer(ATBArena* arena, ActionMap& actions) : + QThread(arena), + m_arena(arena), + m_actionMapper(new QSignalMapper(this)), + m_actions(actions) +{ + connect(m_actionMapper, SIGNAL(mapped(QObject*)), this, SLOT(actionReceived(QObject*))); +} + +ATBTimer::~ATBTimer() +{ +} + +void ATBTimer::run() +{ + startTimer(50); + exec(); +} + +void ATBTimer::timerEvent(QTimerEvent* event) +{ + Q_UNUSED(event) + const QList active = m_arena->active(Arena::Fighters); + QtConcurrent::blockingFiltered(active, TimerIncrementFunctor(this)); +} + +void ATBTimer::actionReceived(QObject* object) +{ + TeamMember* teamMember = qobject_cast(object); + if (teamMember) + emit(actionReady(teamMember)); +} diff --git a/plugins/arena/standard/atb/ATBTimer.h b/plugins/arena/standard/atb/ATBTimer.h new file mode 100644 index 00000000..113d7669 --- /dev/null +++ b/plugins/arena/standard/atb/ATBTimer.h @@ -0,0 +1,58 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 . + */ + +#ifndef SIGENARENAS_ATBTIMER +#define SIGENARENAS_ATBTIMER + +// Sigencore includes +#include + +// Qt includes +#include +#include +#include + +// Forward declarations +class QSignalMapper; +class ActionMap; +class ATBArena; + +class ATBTimer : public QThread +{ + Q_OBJECT + + public: + ATBTimer(ATBArena* arena, ActionMap& actions); + ~ATBTimer(); + signals: + void actionReady(Sigencore::TeamMember* teamMember); + protected: + void run(); + + void timerEvent(QTimerEvent* event); + protected slots: + void actionReceived(QObject* object); + private: + struct TimerIncrementFunctor; + + ATBArena* m_arena; + QSignalMapper* m_actionMapper; + QMap m_timers; + ActionMap& m_actions; +}; + +#endif diff --git a/plugins/arena/standard/atb/ActionMap.cpp b/plugins/arena/standard/atb/ActionMap.cpp new file mode 100644 index 00000000..c5ad49a2 --- /dev/null +++ b/plugins/arena/standard/atb/ActionMap.cpp @@ -0,0 +1,55 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 . + */ + +// Header include +#include "ActionMap.h" + +// Qt includes +#include +#include + +using namespace Sigencore; + +bool ActionMap::contains(TeamMember* teamMember) const +{ + QReadLocker locker(&m_mutex); + return m_map.contains(teamMember); +} + +int ActionMap::remove(TeamMember* teamMember) +{ + QWriteLocker locker(&m_mutex); + return m_map.remove(teamMember); +} + +bool ActionMap::isEmpty() const +{ + QReadLocker locker(&m_mutex); + return m_map.isEmpty(); +} + +void ActionMap::set(TeamMember* teamMember, const TeamMember::RequestedAction& action) +{ + QWriteLocker locker(&m_mutex); + m_map[teamMember] = action; +} + +const TeamMember::RequestedAction ActionMap::operator[](TeamMember* teamMember) const +{ + QReadLocker locker(&m_mutex); + return m_map[teamMember]; +} diff --git a/plugins/arena/standard/atb/ActionMap.h b/plugins/arena/standard/atb/ActionMap.h new file mode 100644 index 00000000..7c65a97e --- /dev/null +++ b/plugins/arena/standard/atb/ActionMap.h @@ -0,0 +1,44 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 . + */ + +#ifndef SIGENARENAS_ACTIONMAP +#define SIGENARENAS_ACTIONMAP + +// Sigencore includes +#include + +// Qt includes +#include +#include + +class ActionMap +{ + public: + bool contains(Sigencore::TeamMember* teamMember) const; + int remove(Sigencore::TeamMember* teamMember); + + bool isEmpty() const; + + void set(Sigencore::TeamMember* teamMember, const Sigencore::TeamMember::RequestedAction& action); + + const Sigencore::TeamMember::RequestedAction operator[](Sigencore::TeamMember* teamMember) const; + private: + QMap m_map; + mutable QReadWriteLock m_mutex; +}; + +#endif diff --git a/plugins/arena/standard/sigen_arenas.desktop b/plugins/arena/standard/sigen_arenas.desktop new file mode 100644 index 00000000..e4f659c7 --- /dev/null +++ b/plugins/arena/standard/sigen_arenas.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Type=Service +X-KDE-ServiceTypes=Sigen/Arena +Icon=sigen-arenaplugin +Name=Sigen Arenas +X-Sigen-MinVersion=000101 +X-KDE-Library=arena_sigen +X-KDE-PluginInfo-Author=Ben Boeckel +X-KDE-PluginInfo-Email=MathStuf@gmail.com +X-KDE-PluginInfo-Name=sigen_arenas +X-KDE-PluginInfo-Version=0.1.1 +X-KDE-PluginInfo-Website= +X-KDE-PluginInfo-Category=arena +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPLv3 +X-KDE-PluginInfo-EnabledByDefault=true diff --git a/plugins/arena/standard/standard/TurnArena.cpp b/plugins/arena/standard/standard/TurnArena.cpp new file mode 100644 index 00000000..233e512f --- /dev/null +++ b/plugins/arena/standard/standard/TurnArena.cpp @@ -0,0 +1,160 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 . + */ + +// Header include +#include "TurnArena.h" + +// Sigencore includes +#include +#include +#include + +// Sigscript includes +#include +#include + +// KDE includes +#include +#include + +// Qt includes +#include +#include +#include +#include + +using namespace Sigcore; +using namespace Sigscript; +using namespace Sigencore; + +bool sortActions(const TeamMember::RequestedAction& reqAction1, const TeamMember::RequestedAction& reqAction2) +{ + TeamMember::Action action1 = reqAction1.second.isCanceled() ? TeamMember::Action(TeamMember::Timeout, TeamMember::ActionData()) : reqAction1.second; + TeamMember::Action action2 = reqAction2.second.isCanceled() ? TeamMember::Action(TeamMember::Timeout, TeamMember::ActionData()) : reqAction2.second; + const int priority1 = actionPriority(reqAction1.first, action1); + const int priority2 = actionPriority(reqAction1.first, action2); + if (priority1 < priority2) + return true; + else if (priority1 == priority2) + { + const int speed1 = reqAction1.first->statValue(Sigmod::ST_Speed); + const int speed2 = reqAction2.first->statValue(Sigmod::ST_Speed); + if (speed1 < speed2) + return true; + else if (speed1 == speed2) + return Sigcore::Fraction::poll(1, 2); + } + return false; +} + +TurnArena::TurnArena(GameWrapper* sigmod, Config* parent) : + Arena(sigmod, parent), + m_priorityScripts(new Kross::ActionCollection("priority-scripts", m_actions)) +{ + setupBattle(); +} + +QString TurnArena::name() +{ + return "Sigen turn arena"; +} + +QString TurnArena::description() +{ + return "An arena where creatures act in order of their speed (unless move priority takes precedence)"; +} + +QIcon TurnArena::icon() +{ + // TODO + return KIcon(); +} + +bool TurnArena::isTeamAllowed(Sigencore::Team* team) +{ + Q_UNUSED(team) + // TODO: Use rules format here? + return true; +} + +void TurnArena::handleAction(TeamMember* teamMember, TeamMember::Action action) +{ + Arena::handleAction(teamMember, action); +} + +void TurnArena::setupBattle() +{ + connect(this, SIGNAL(battleStarted()), SLOT(processRound())); + Arena::setupBattle(); +} + +void TurnArena::distributeWinnings() +{ + Arena::distributeWinnings(); +} + +void TurnArena::checkForLosers() +{ + Arena::checkForLosers(); +} + +void TurnArena::registerScript(const Script& script) +{ + Arena::registerScript(script); +} + +void TurnArena::cleanUp() +{ + Arena::cleanUp(); +} + +void TurnArena::processRound() +{ + emit(roundAboutToStart()); + emit(roundStarted()); + QFuture reqActions = QtConcurrent::mapped(active(Fighters), &requestDecision); + reqActions.waitForFinished(); + QList actions = reqActions.results(); + qStableSort(actions.begin(), actions.end(), sortActions); + foreach (const TeamMember::RequestedAction& reqAction, actions) + { + TeamMember::Action action = reqAction.second; + if (action.first == TeamMember::Attack) + { + MoveWrapper* move = m_game->move(action.second.first.toInt()); + const Script script = move->priorityScript(); + ObjectMap objects; + objects["arena"] = this; + objects["move"] = move; + objects["owner"] = reqAction.first; + objects["player"] = reqAction.first->team()->player(); + objects["sigmod"] = m_game; + // TODO: Add other players + runScript(QString("priority-%1").arg(QUuid::createUuid().toString()), script, objects, m_priorityScripts)->trigger(); + } + } + qStableSort(actions.begin(), actions.end(), sortActions); + foreach (const TeamMember::RequestedAction& action, actions) + { + if (action.first->currentHp()) + handleAction(action.first, action.second); + } + emit(roundAboutToEnd()); + emit(roundEnded()); + // TODO: Check if there is anyone left to fight + processRound(); +} diff --git a/plugins/arena/standard/standard/TurnArena.h b/plugins/arena/standard/standard/TurnArena.h new file mode 100644 index 00000000..9dce6ea3 --- /dev/null +++ b/plugins/arena/standard/standard/TurnArena.h @@ -0,0 +1,60 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * 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 . + */ + +#ifndef SIGENARENAS_TURNARENA +#define SIGENARENAS_TURNARENA + +// Sigencore includes +#include + +class TurnArena : public Sigencore::Arena +{ + Q_OBJECT + + public: + TurnArena(Sigscript::GameWrapper* game, Sigscript::Config* parent); + + static QString name(); + static QString description(); + static QIcon icon(); + signals: + void roundAboutToStart(); + void roundStarted(); + void roundEnded(); + void roundAboutToEnd(); + protected: + virtual void handleAction(Sigencore::TeamMember* teamMember, Sigencore::TeamMember::Action action); + + virtual bool isTeamAllowed(Sigencore::Team* team); + + virtual void setupBattle(); + + virtual void distributeWinnings(); + virtual void checkForLosers(); + + Kross::ActionCollection* m_priorityScripts; + protected slots: + void processRound(); + + virtual void registerScript(const Sigcore::Script& script); + + virtual void cleanUp(); +}; + +bool sortActions(const Sigencore::TeamMember::RequestedAction& reqAction1, const Sigencore::TeamMember::RequestedAction& reqAction2); + +#endif diff --git a/plugins/canvas/CMakeLists.txt b/plugins/canvas/CMakeLists.txt new file mode 100644 index 00000000..a0b57536 --- /dev/null +++ b/plugins/canvas/CMakeLists.txt @@ -0,0 +1,3 @@ +project(plugins) + +add_subdirectory(standard) diff --git a/plugins/canvas/standard/CMakeLists.txt b/plugins/canvas/standard/CMakeLists.txt new file mode 100644 index 00000000..931659d4 --- /dev/null +++ b/plugins/canvas/standard/CMakeLists.txt @@ -0,0 +1,38 @@ +project(sigencanvases) + +set(sigencanvases_SRCS + SigenCanvases.cpp + qgraphicsscene/QGSCanvas.cpp +) +set(sigencanvases_SERVICES + sigen_canvases.desktop +) + +kde4_add_plugin(canvas_sigen + ${sigencanvases_SRCS} +) +target_link_libraries(canvas_sigen + ${QT_QTCORE_LIBRARY} + ${QT_QTGUI_LIBRARY} + ${KDE4_KDEUI_LIBRARY} + ${KDE4_KROSSCORE_LIBRARY} + sigencoreplugins +) + +install( + TARGETS + canvas_sigen + DESTINATION + ${PLUGIN_INSTALL_DIR} + COMPONENT + plugins +) + +install( + FILES + ${sigencanvases_SERVICES} + DESTINATION + ${SERVICES_INSTALL_DIR} + COMPONENT + plugins +) diff --git a/plugins/canvas/standard/SigenCanvases.cpp b/plugins/canvas/standard/SigenCanvases.cpp new file mode 100644 index 00000000..3969a56e --- /dev/null +++ b/plugins/canvas/standard/SigenCanvases.cpp @@ -0,0 +1,79 @@ +/* + * Copyright 2009 Ben Boeckel + * + * 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 . + */ + +// Header include +#include "SigenCanvases.h" + +// Canvas includes +#include "qgraphicsscene/QGSCanvas.h" + +// Sigencore includes +#include + +// KDE includes +#include + +SIGEN_CANVAS_PLUGIN_VERSION(SigenCanvases, "sigen_canvases", 000101) + +using namespace Sigscript; +using namespace Sigencore; +using namespace Sigencore::Plugins; + +SigenCanvases::SigenCanvases(QObject* parent, const QVariantList& args) : + CanvasPlugin(parent, args) +{ +} + +SigenCanvases::~SigenCanvases() +{ +} + +QStringList SigenCanvases::classList() const +{ + return QStringList() << QGSCanvas::name(); +} + +QString SigenCanvases::description(const QString& name) const +{ + if (name == QGSCanvas::name()) + return QGSCanvas::description(); + return "(Unknown canvas)"; +} + +QIcon SigenCanvases::icon(const QString& name) +{ + if (name == QGSCanvas::name()) + return QGSCanvas::icon(); + return KIcon(); +} + +Canvas* SigenCanvases::createCanvas(const QString& name, GameWrapper* game, Config* parent) +{ + if (name == QGSCanvas::name()) + return new QGSCanvas(game, parent); + return NULL; +} + +void SigenCanvases::cleanupCanvas(Canvas* canvas) +{ + QGSCanvas* qgsCanvas = qobject_cast(canvas); + if (qgsCanvas) + { + delete qgsCanvas; + return; + } +} diff --git a/plugins/canvas/standard/SigenCanvases.h b/plugins/canvas/standard/SigenCanvases.h new file mode 100644 index 00000000..6e0eaf22 --- /dev/null +++ b/plugins/canvas/standard/SigenCanvases.h @@ -0,0 +1,41 @@ +/* + * Copyright 2009 Ben Boeckel + * + * 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 . + */ + +#ifndef SIGENCANVASES_SIGENCANVASES +#define SIGENCANVASES_SIGENCANVASES + +// Sigencore plugin includes +#include + +class SigenCanvases : public Sigencore::Plugins::CanvasPlugin +{ + Q_OBJECT + + public: + SigenCanvases(QObject* parent, const QVariantList& args); + ~SigenCanvases(); + + QStringList classList() const; + QString description(const QString& name) const; + QIcon icon(const QString& name); + protected: + Sigencore::Canvas* createCanvas(const QString& name, Sigscript::GameWrapper* game, Sigscript::Config* parent); + protected slots: + void cleanupCanvas(Sigencore::Canvas* canvas); +}; + +#endif diff --git a/plugins/canvas/standard/qgraphicsscene/QGSCanvas.cpp b/plugins/canvas/standard/qgraphicsscene/QGSCanvas.cpp new file mode 100644 index 00000000..09f823b1 --- /dev/null +++ b/plugins/canvas/standard/qgraphicsscene/QGSCanvas.cpp @@ -0,0 +1,112 @@ +/* + * Copyright 2009 Ben Boeckel + * + * 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 . + */ + +// Header include +#include "QGSCanvas.h" + +// Sigencore includes +#include + +// Sigscript includes +#include +#include + +// KDE includes +#include +#include +#include +#include + +// Qt includes +#include +#include +#include +#include + +using namespace Sigscript; +using namespace Sigencore; + +QGSCanvas::QGSCanvas(GameWrapper* game, Config* parent) : + Canvas(parent), + m_game(game), + m_scene(new QGraphicsScene), + m_collection(new Kross::ActionCollection(QString("canvas-%1").arg(QUuid::createUuid().toString()), Kross::Manager::self().actionCollection())) +{ +} + +QGSCanvas::~QGSCanvas() +{ + delete m_scene; + delete m_collection; +} + +QString QGSCanvas::name() +{ + return "QGraphicsScene canvas"; +} + +QString QGSCanvas::description() +{ + return "A canvas using QGraphicsScene"; +} + +QIcon QGSCanvas::icon() +{ + return KIcon(); +} + +void QGSCanvas::addSprite(const QString& name, const QString& sprite, const int x, const int y, const int zOrder) +{ + // TODO: NOOP or refresh? + if (m_items.contains(name)) + return; + SpriteWrapper* spr = m_game->sprite(sprite); + if (spr) + { + QGraphicsPixmapItem* item = new QGraphicsPixmapItem(spr->sprite()); + item->setPos(x, y); + item->setZValue(zOrder); + m_scene->addItem(item); + m_items[name] = item; + } +} + +void QGSCanvas::removeSprite(const QString& name) +{ + if (m_items.contains(name)) + { + delete m_items[name]; + m_items.remove(name); + } +} + +void QGSCanvas::transform(const QString& transform, const QString& object, const QVariantList& parameters) +{ +} + +int QGSCanvas::type() const +{ + return QGraphicsSceneCanvas; +} + +QWidget* QGSCanvas::viewport() +{ + // TODO: Only one view allowed? or as many as wanted? + QGraphicsView* view = new QGraphicsView; + view->setScene(m_scene); + return view; +} diff --git a/plugins/canvas/standard/qgraphicsscene/QGSCanvas.h b/plugins/canvas/standard/qgraphicsscene/QGSCanvas.h new file mode 100644 index 00000000..d779a3b3 --- /dev/null +++ b/plugins/canvas/standard/qgraphicsscene/QGSCanvas.h @@ -0,0 +1,62 @@ +/* + * Copyright 2009 Ben Boeckel + * + * 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 . + */ + +#ifndef SIGENCANVASES_QGSCANVAS +#define SIGENCANVASES_QGSCANVAS + +// Sigencore includes +#include + +// Forward declarations +namespace Kross +{ +class ActionCollection; +} +class QGraphicsItem; +class QGraphicsScene; +namespace Sigscript +{ +class GameWrapper; +} + +class QGSCanvas : public Sigencore::Canvas +{ + Q_OBJECT + + public: + QGSCanvas(Sigscript::GameWrapper* game, Sigscript::Config* parent); + ~QGSCanvas(); + + static QString name(); + static QString description(); + static QIcon icon(); + + Q_SCRIPTABLE void addSprite(const QString& name, const QString& sprite, const int x, const int y, const int zOrder); + Q_SCRIPTABLE void removeSprite(const QString& name); + Q_SCRIPTABLE void transform(const QString& transform, const QString& object, const QVariantList& parameters); + + int type() const; + + QWidget* viewport(); + private: + Sigscript::GameWrapper* m_game; + QGraphicsScene* m_scene; + QMap m_items; + Kross::ActionCollection* m_collection; +}; + +#endif diff --git a/plugins/canvas/standard/sigen_canvases.desktop b/plugins/canvas/standard/sigen_canvases.desktop new file mode 100644 index 00000000..7731030c --- /dev/null +++ b/plugins/canvas/standard/sigen_canvases.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Type=Service +X-KDE-ServiceTypes=Sigen/Canvas +Icon=sigen-canvasplugin +Name=Sigen Canvases +X-Sigen-MinVersion=0.1.1 +X-KDE-Library=canvas_sigen +X-KDE-PluginInfo-Author=Ben Boeckel +X-KDE-PluginInfo-Email=MathStuf@gmail.com +X-KDE-PluginInfo-Name=sigen_canvas +X-KDE-PluginInfo-Version=0.1.1 +X-KDE-PluginInfo-Website= +X-KDE-PluginInfo-Category=canvas +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPLv3 +X-KDE-PluginInfo-EnabledByDefault=true diff --git a/plugins/sigen_arena_standard/CMakeLists.txt b/plugins/sigen_arena_standard/CMakeLists.txt deleted file mode 100644 index de972424..00000000 --- a/plugins/sigen_arena_standard/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -project(sigenarenas) - -set(sigenarenas_SRCS - SigenArenas.cpp - atb/ActionMap.cpp - atb/ATBArena.cpp - atb/ATBTimer.cpp - standard/TurnArena.cpp -) -set(sigenarenas_SERVICES - sigen_arenas.desktop -) - -kde4_add_plugin(arena_sigen - ${sigenarenas_SRCS} -) -target_link_libraries(arena_sigen - ${QT_QTCORE_LIBRARY} - ${KDE4_KDEUI_LIBRARY} - ${KDE4_KROSSCORE_LIBRARY} - sigencoreplugins -) - -install( - TARGETS - arena_sigen - DESTINATION - ${PLUGIN_INSTALL_DIR} - COMPONENT - plugins -) - -install( - FILES - ${sigenarenas_SERVICES} - DESTINATION - ${SERVICES_INSTALL_DIR} - COMPONENT - plugins -) diff --git a/plugins/sigen_arena_standard/SigenArenas.cpp b/plugins/sigen_arena_standard/SigenArenas.cpp deleted file mode 100644 index faf3f848..00000000 --- a/plugins/sigen_arena_standard/SigenArenas.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2009 Ben Boeckel - * - * 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 . - */ - -// Header include -#include "SigenArenas.h" - -// Arena includes -#include "standard/TurnArena.h" -#include "atb/ATBArena.h" - -// Sigencore includes -#include - -// KDE includes -#include - -SIGEN_ARENA_PLUGIN_VERSION(SigenArenas, "sigen_arenas", 000101) - -using namespace Sigscript; -using namespace Sigencore; -using namespace Sigencore::Plugins; - -SigenArenas::SigenArenas(QObject* parent, const QVariantList& args) : - ArenaPlugin(parent, args) -{ -} - -SigenArenas::~SigenArenas() -{ -} - -QStringList SigenArenas::classList() const -{ - return QStringList() << TurnArena::name() << ATBArena::name(); -} - -QString SigenArenas::description(const QString& name) const -{ - if (name == TurnArena::name()) - return TurnArena::description(); - if (name == ATBArena::name()) - return ATBArena::description(); - return "(Unknown arena)"; -} - -QIcon SigenArenas::icon(const QString& name) -{ - if (name == TurnArena::name()) - return TurnArena::icon(); - if (name == ATBArena::name()) - return ATBArena::icon(); - return KIcon(); -} - -Arena* SigenArenas::createArena(const QString& name, GameWrapper* game, Config* parent) -{ - if (name == TurnArena::name()) - return new TurnArena(game, parent); - if (name == ATBArena::name()) - return new ATBArena(game, parent); - return NULL; -} - -void SigenArenas::cleanupArena(Arena* arena) -{ - TurnArena* turnArena = qobject_cast(arena); - if (turnArena) - { - delete turnArena; - return; - } - ATBArena* atbArena = qobject_cast(arena); - if (atbArena) - { - delete atbArena; - return; - } -} diff --git a/plugins/sigen_arena_standard/SigenArenas.h b/plugins/sigen_arena_standard/SigenArenas.h deleted file mode 100644 index 14ce15c8..00000000 --- a/plugins/sigen_arena_standard/SigenArenas.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2009 Ben Boeckel - * - * 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 . - */ - -#ifndef SIGENARENAS_SIGENARENAS -#define SIGENARENAS_SIGENARENAS - -// Sigencore plugin includes -#include - -class SigenArenas : public Sigencore::Plugins::ArenaPlugin -{ - Q_OBJECT - - public: - SigenArenas(QObject* parent, const QVariantList& args); - ~SigenArenas(); - - QStringList classList() const; - QString description(const QString& name) const; - QIcon icon(const QString& name); - protected: - Sigencore::Arena* createArena(const QString& name, Sigscript::GameWrapper* game, Sigscript::Config* parent); - protected slots: - void cleanupArena(Sigencore::Arena* arena); -}; - -#endif diff --git a/plugins/sigen_arena_standard/atb/ATBArena.cpp b/plugins/sigen_arena_standard/atb/ATBArena.cpp deleted file mode 100644 index 21fd1914..00000000 --- a/plugins/sigen_arena_standard/atb/ATBArena.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * 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 . - */ - -// Header includes -#include "ATBArena.h" - -// Sigbattle includes -#include "ATBTimer.h" - -// KDE includes -#include - -// Qt includes -#include -#include - -using namespace Sigscript; -using namespace Sigencore; - -ATBArena::ATBArena(GameWrapper* sigmod, Config* parent) : - Arena(sigmod, parent), - m_atbTimer(new ATBTimer(this, m_decisions)) -{ - connect(m_atbTimer, SIGNAL(actionReady(Sigencore::TeamMember*)), this, SLOT(processAction(Sigencore::TeamMember*))); - setupBattle(); -} - -ATBArena::~ATBArena() -{ -} - -QString ATBArena::name() -{ - return "Sigen ATB Arena"; -} - -QString ATBArena::description() -{ - return "An arena where creatures have an action bar which when filled, can act"; -} - -QIcon ATBArena::icon() -{ - // TODO - return KIcon(); -} - -void ATBArena::handleAction(TeamMember* teamMember, TeamMember::Action action) -{ - if ((action.first == TeamMember::Invalid) || (action.first == TeamMember::Timeout)) - return; - Arena::handleAction(teamMember, action); -} - -bool ATBArena::isTeamAllowed(Sigencore::Team* team) -{ - Q_UNUSED(team) - // TODO: Use rules format here? - return true; -} - -void ATBArena::setupBattle() -{ - Arena::setupBattle(); -} - -void ATBArena::processAction(TeamMember* teamMember) -{ - handleAction(teamMember, m_decisions[teamMember].second); - m_decisions.remove(teamMember); -} - -void ATBArena::cleanUp() -{ - Arena::cleanUp(); -} diff --git a/plugins/sigen_arena_standard/atb/ATBArena.h b/plugins/sigen_arena_standard/atb/ATBArena.h deleted file mode 100644 index 7e6e5b08..00000000 --- a/plugins/sigen_arena_standard/atb/ATBArena.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * 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 . - */ - -#ifndef SIGENARENAS_ATBARENA -#define SIGENARENAS_ATBARENA - -// ATB includes -#include "ActionMap.h" - -// Sigencore includes -#include - -// Forward declaraions -class QTimer; -class ATBTimer; - -class ATBArena : public Sigencore::Arena -{ - Q_OBJECT - - public: - ATBArena(Sigscript::GameWrapper* game, Sigscript::Config* parent); - ~ATBArena(); - - static QString name(); - static QString description(); - static QIcon icon(); - protected: - virtual void handleAction(Sigencore::TeamMember* teamMember, Sigencore::TeamMember::Action action); - - virtual bool isTeamAllowed(Sigencore::Team* team); - - virtual void setupBattle(); - - Kross::ActionCollection* m_priorityScripts; - protected slots: - void processAction(Sigencore::TeamMember* teamMember); - - virtual void cleanUp(); - private: - ActionMap m_decisions; - ATBTimer* m_atbTimer; -}; - -#endif diff --git a/plugins/sigen_arena_standard/atb/ATBTimer.cpp b/plugins/sigen_arena_standard/atb/ATBTimer.cpp deleted file mode 100644 index adb2a853..00000000 --- a/plugins/sigen_arena_standard/atb/ATBTimer.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * 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 . - */ - -// Header include -#include "ATBTimer.h" - -// ATB includes -#include "ActionMap.h" -#include "ATBArena.h" - -// Sigscript includes -#include -#include - -// Qt includes -#include -#include -#include -#include - -using namespace Sigencore; - -struct ATBTimer::TimerIncrementFunctor -{ - TimerIncrementFunctor(ATBTimer* timer) : - m_timer(timer) - { - } - - typedef bool result_type; - - bool operator()(TeamMember* teamMember) - { - double factor = .1; - m_timer->m_arena->valueOfType("meter-factor", &factor); - if (!m_timer->m_actions.contains(teamMember)) - { - m_timer->m_timers[teamMember] += teamMember->statValue(Sigmod::ST_Speed) * factor; - int threshold = 1000; - m_timer->m_arena->valueOfType("meter-threshold", &threshold); - if (threshold <= m_timer->m_timers[teamMember]) - { - QFutureWatcher* watcher = new QFutureWatcher(m_timer); - TeamMember::RequestedAction action = requestDecision(teamMember); - watcher->setFuture(action.second); - m_timer->connect(watcher, SIGNAL(finished()), m_timer->m_actionMapper, SLOT(map())); - m_timer->connect(watcher, SIGNAL(finished()), SLOT(deleteLater())); - m_timer->m_actionMapper->setMapping(watcher, teamMember); - m_timer->m_actions.set(teamMember, action); - } - } - return false; - } - - ATBTimer* m_timer; -}; - -ATBTimer::ATBTimer(ATBArena* arena, ActionMap& actions) : - QThread(arena), - m_arena(arena), - m_actionMapper(new QSignalMapper(this)), - m_actions(actions) -{ - connect(m_actionMapper, SIGNAL(mapped(QObject*)), this, SLOT(actionReceived(QObject*))); -} - -ATBTimer::~ATBTimer() -{ -} - -void ATBTimer::run() -{ - startTimer(50); - exec(); -} - -void ATBTimer::timerEvent(QTimerEvent* event) -{ - Q_UNUSED(event) - const QList active = m_arena->active(Arena::Fighters); - QtConcurrent::blockingFiltered(active, TimerIncrementFunctor(this)); -} - -void ATBTimer::actionReceived(QObject* object) -{ - TeamMember* teamMember = qobject_cast(object); - if (teamMember) - emit(actionReady(teamMember)); -} diff --git a/plugins/sigen_arena_standard/atb/ATBTimer.h b/plugins/sigen_arena_standard/atb/ATBTimer.h deleted file mode 100644 index 113d7669..00000000 --- a/plugins/sigen_arena_standard/atb/ATBTimer.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * 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 . - */ - -#ifndef SIGENARENAS_ATBTIMER -#define SIGENARENAS_ATBTIMER - -// Sigencore includes -#include - -// Qt includes -#include -#include -#include - -// Forward declarations -class QSignalMapper; -class ActionMap; -class ATBArena; - -class ATBTimer : public QThread -{ - Q_OBJECT - - public: - ATBTimer(ATBArena* arena, ActionMap& actions); - ~ATBTimer(); - signals: - void actionReady(Sigencore::TeamMember* teamMember); - protected: - void run(); - - void timerEvent(QTimerEvent* event); - protected slots: - void actionReceived(QObject* object); - private: - struct TimerIncrementFunctor; - - ATBArena* m_arena; - QSignalMapper* m_actionMapper; - QMap m_timers; - ActionMap& m_actions; -}; - -#endif diff --git a/plugins/sigen_arena_standard/atb/ActionMap.cpp b/plugins/sigen_arena_standard/atb/ActionMap.cpp deleted file mode 100644 index c5ad49a2..00000000 --- a/plugins/sigen_arena_standard/atb/ActionMap.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * 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 . - */ - -// Header include -#include "ActionMap.h" - -// Qt includes -#include -#include - -using namespace Sigencore; - -bool ActionMap::contains(TeamMember* teamMember) const -{ - QReadLocker locker(&m_mutex); - return m_map.contains(teamMember); -} - -int ActionMap::remove(TeamMember* teamMember) -{ - QWriteLocker locker(&m_mutex); - return m_map.remove(teamMember); -} - -bool ActionMap::isEmpty() const -{ - QReadLocker locker(&m_mutex); - return m_map.isEmpty(); -} - -void ActionMap::set(TeamMember* teamMember, const TeamMember::RequestedAction& action) -{ - QWriteLocker locker(&m_mutex); - m_map[teamMember] = action; -} - -const TeamMember::RequestedAction ActionMap::operator[](TeamMember* teamMember) const -{ - QReadLocker locker(&m_mutex); - return m_map[teamMember]; -} diff --git a/plugins/sigen_arena_standard/atb/ActionMap.h b/plugins/sigen_arena_standard/atb/ActionMap.h deleted file mode 100644 index 7c65a97e..00000000 --- a/plugins/sigen_arena_standard/atb/ActionMap.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * 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 . - */ - -#ifndef SIGENARENAS_ACTIONMAP -#define SIGENARENAS_ACTIONMAP - -// Sigencore includes -#include - -// Qt includes -#include -#include - -class ActionMap -{ - public: - bool contains(Sigencore::TeamMember* teamMember) const; - int remove(Sigencore::TeamMember* teamMember); - - bool isEmpty() const; - - void set(Sigencore::TeamMember* teamMember, const Sigencore::TeamMember::RequestedAction& action); - - const Sigencore::TeamMember::RequestedAction operator[](Sigencore::TeamMember* teamMember) const; - private: - QMap m_map; - mutable QReadWriteLock m_mutex; -}; - -#endif diff --git a/plugins/sigen_arena_standard/sigen_arenas.desktop b/plugins/sigen_arena_standard/sigen_arenas.desktop deleted file mode 100644 index e4f659c7..00000000 --- a/plugins/sigen_arena_standard/sigen_arenas.desktop +++ /dev/null @@ -1,16 +0,0 @@ -[Desktop Entry] -Type=Service -X-KDE-ServiceTypes=Sigen/Arena -Icon=sigen-arenaplugin -Name=Sigen Arenas -X-Sigen-MinVersion=000101 -X-KDE-Library=arena_sigen -X-KDE-PluginInfo-Author=Ben Boeckel -X-KDE-PluginInfo-Email=MathStuf@gmail.com -X-KDE-PluginInfo-Name=sigen_arenas -X-KDE-PluginInfo-Version=0.1.1 -X-KDE-PluginInfo-Website= -X-KDE-PluginInfo-Category=arena -X-KDE-PluginInfo-Depends= -X-KDE-PluginInfo-License=GPLv3 -X-KDE-PluginInfo-EnabledByDefault=true diff --git a/plugins/sigen_arena_standard/standard/TurnArena.cpp b/plugins/sigen_arena_standard/standard/TurnArena.cpp deleted file mode 100644 index 233e512f..00000000 --- a/plugins/sigen_arena_standard/standard/TurnArena.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * 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 . - */ - -// Header include -#include "TurnArena.h" - -// Sigencore includes -#include -#include -#include - -// Sigscript includes -#include -#include - -// KDE includes -#include -#include - -// Qt includes -#include -#include -#include -#include - -using namespace Sigcore; -using namespace Sigscript; -using namespace Sigencore; - -bool sortActions(const TeamMember::RequestedAction& reqAction1, const TeamMember::RequestedAction& reqAction2) -{ - TeamMember::Action action1 = reqAction1.second.isCanceled() ? TeamMember::Action(TeamMember::Timeout, TeamMember::ActionData()) : reqAction1.second; - TeamMember::Action action2 = reqAction2.second.isCanceled() ? TeamMember::Action(TeamMember::Timeout, TeamMember::ActionData()) : reqAction2.second; - const int priority1 = actionPriority(reqAction1.first, action1); - const int priority2 = actionPriority(reqAction1.first, action2); - if (priority1 < priority2) - return true; - else if (priority1 == priority2) - { - const int speed1 = reqAction1.first->statValue(Sigmod::ST_Speed); - const int speed2 = reqAction2.first->statValue(Sigmod::ST_Speed); - if (speed1 < speed2) - return true; - else if (speed1 == speed2) - return Sigcore::Fraction::poll(1, 2); - } - return false; -} - -TurnArena::TurnArena(GameWrapper* sigmod, Config* parent) : - Arena(sigmod, parent), - m_priorityScripts(new Kross::ActionCollection("priority-scripts", m_actions)) -{ - setupBattle(); -} - -QString TurnArena::name() -{ - return "Sigen turn arena"; -} - -QString TurnArena::description() -{ - return "An arena where creatures act in order of their speed (unless move priority takes precedence)"; -} - -QIcon TurnArena::icon() -{ - // TODO - return KIcon(); -} - -bool TurnArena::isTeamAllowed(Sigencore::Team* team) -{ - Q_UNUSED(team) - // TODO: Use rules format here? - return true; -} - -void TurnArena::handleAction(TeamMember* teamMember, TeamMember::Action action) -{ - Arena::handleAction(teamMember, action); -} - -void TurnArena::setupBattle() -{ - connect(this, SIGNAL(battleStarted()), SLOT(processRound())); - Arena::setupBattle(); -} - -void TurnArena::distributeWinnings() -{ - Arena::distributeWinnings(); -} - -void TurnArena::checkForLosers() -{ - Arena::checkForLosers(); -} - -void TurnArena::registerScript(const Script& script) -{ - Arena::registerScript(script); -} - -void TurnArena::cleanUp() -{ - Arena::cleanUp(); -} - -void TurnArena::processRound() -{ - emit(roundAboutToStart()); - emit(roundStarted()); - QFuture reqActions = QtConcurrent::mapped(active(Fighters), &requestDecision); - reqActions.waitForFinished(); - QList actions = reqActions.results(); - qStableSort(actions.begin(), actions.end(), sortActions); - foreach (const TeamMember::RequestedAction& reqAction, actions) - { - TeamMember::Action action = reqAction.second; - if (action.first == TeamMember::Attack) - { - MoveWrapper* move = m_game->move(action.second.first.toInt()); - const Script script = move->priorityScript(); - ObjectMap objects; - objects["arena"] = this; - objects["move"] = move; - objects["owner"] = reqAction.first; - objects["player"] = reqAction.first->team()->player(); - objects["sigmod"] = m_game; - // TODO: Add other players - runScript(QString("priority-%1").arg(QUuid::createUuid().toString()), script, objects, m_priorityScripts)->trigger(); - } - } - qStableSort(actions.begin(), actions.end(), sortActions); - foreach (const TeamMember::RequestedAction& action, actions) - { - if (action.first->currentHp()) - handleAction(action.first, action.second); - } - emit(roundAboutToEnd()); - emit(roundEnded()); - // TODO: Check if there is anyone left to fight - processRound(); -} diff --git a/plugins/sigen_arena_standard/standard/TurnArena.h b/plugins/sigen_arena_standard/standard/TurnArena.h deleted file mode 100644 index 9dce6ea3..00000000 --- a/plugins/sigen_arena_standard/standard/TurnArena.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * 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 . - */ - -#ifndef SIGENARENAS_TURNARENA -#define SIGENARENAS_TURNARENA - -// Sigencore includes -#include - -class TurnArena : public Sigencore::Arena -{ - Q_OBJECT - - public: - TurnArena(Sigscript::GameWrapper* game, Sigscript::Config* parent); - - static QString name(); - static QString description(); - static QIcon icon(); - signals: - void roundAboutToStart(); - void roundStarted(); - void roundEnded(); - void roundAboutToEnd(); - protected: - virtual void handleAction(Sigencore::TeamMember* teamMember, Sigencore::TeamMember::Action action); - - virtual bool isTeamAllowed(Sigencore::Team* team); - - virtual void setupBattle(); - - virtual void distributeWinnings(); - virtual void checkForLosers(); - - Kross::ActionCollection* m_priorityScripts; - protected slots: - void processRound(); - - virtual void registerScript(const Sigcore::Script& script); - - virtual void cleanUp(); -}; - -bool sortActions(const Sigencore::TeamMember::RequestedAction& reqAction1, const Sigencore::TeamMember::RequestedAction& reqAction2); - -#endif diff --git a/plugins/sigen_canvas_standard/CMakeLists.txt b/plugins/sigen_canvas_standard/CMakeLists.txt deleted file mode 100644 index 931659d4..00000000 --- a/plugins/sigen_canvas_standard/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -project(sigencanvases) - -set(sigencanvases_SRCS - SigenCanvases.cpp - qgraphicsscene/QGSCanvas.cpp -) -set(sigencanvases_SERVICES - sigen_canvases.desktop -) - -kde4_add_plugin(canvas_sigen - ${sigencanvases_SRCS} -) -target_link_libraries(canvas_sigen - ${QT_QTCORE_LIBRARY} - ${QT_QTGUI_LIBRARY} - ${KDE4_KDEUI_LIBRARY} - ${KDE4_KROSSCORE_LIBRARY} - sigencoreplugins -) - -install( - TARGETS - canvas_sigen - DESTINATION - ${PLUGIN_INSTALL_DIR} - COMPONENT - plugins -) - -install( - FILES - ${sigencanvases_SERVICES} - DESTINATION - ${SERVICES_INSTALL_DIR} - COMPONENT - plugins -) diff --git a/plugins/sigen_canvas_standard/SigenCanvases.cpp b/plugins/sigen_canvas_standard/SigenCanvases.cpp deleted file mode 100644 index 3969a56e..00000000 --- a/plugins/sigen_canvas_standard/SigenCanvases.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2009 Ben Boeckel - * - * 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 . - */ - -// Header include -#include "SigenCanvases.h" - -// Canvas includes -#include "qgraphicsscene/QGSCanvas.h" - -// Sigencore includes -#include - -// KDE includes -#include - -SIGEN_CANVAS_PLUGIN_VERSION(SigenCanvases, "sigen_canvases", 000101) - -using namespace Sigscript; -using namespace Sigencore; -using namespace Sigencore::Plugins; - -SigenCanvases::SigenCanvases(QObject* parent, const QVariantList& args) : - CanvasPlugin(parent, args) -{ -} - -SigenCanvases::~SigenCanvases() -{ -} - -QStringList SigenCanvases::classList() const -{ - return QStringList() << QGSCanvas::name(); -} - -QString SigenCanvases::description(const QString& name) const -{ - if (name == QGSCanvas::name()) - return QGSCanvas::description(); - return "(Unknown canvas)"; -} - -QIcon SigenCanvases::icon(const QString& name) -{ - if (name == QGSCanvas::name()) - return QGSCanvas::icon(); - return KIcon(); -} - -Canvas* SigenCanvases::createCanvas(const QString& name, GameWrapper* game, Config* parent) -{ - if (name == QGSCanvas::name()) - return new QGSCanvas(game, parent); - return NULL; -} - -void SigenCanvases::cleanupCanvas(Canvas* canvas) -{ - QGSCanvas* qgsCanvas = qobject_cast(canvas); - if (qgsCanvas) - { - delete qgsCanvas; - return; - } -} diff --git a/plugins/sigen_canvas_standard/SigenCanvases.h b/plugins/sigen_canvas_standard/SigenCanvases.h deleted file mode 100644 index 6e0eaf22..00000000 --- a/plugins/sigen_canvas_standard/SigenCanvases.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2009 Ben Boeckel - * - * 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 . - */ - -#ifndef SIGENCANVASES_SIGENCANVASES -#define SIGENCANVASES_SIGENCANVASES - -// Sigencore plugin includes -#include - -class SigenCanvases : public Sigencore::Plugins::CanvasPlugin -{ - Q_OBJECT - - public: - SigenCanvases(QObject* parent, const QVariantList& args); - ~SigenCanvases(); - - QStringList classList() const; - QString description(const QString& name) const; - QIcon icon(const QString& name); - protected: - Sigencore::Canvas* createCanvas(const QString& name, Sigscript::GameWrapper* game, Sigscript::Config* parent); - protected slots: - void cleanupCanvas(Sigencore::Canvas* canvas); -}; - -#endif diff --git a/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.cpp b/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.cpp deleted file mode 100644 index 09f823b1..00000000 --- a/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2009 Ben Boeckel - * - * 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 . - */ - -// Header include -#include "QGSCanvas.h" - -// Sigencore includes -#include - -// Sigscript includes -#include -#include - -// KDE includes -#include -#include -#include -#include - -// Qt includes -#include -#include -#include -#include - -using namespace Sigscript; -using namespace Sigencore; - -QGSCanvas::QGSCanvas(GameWrapper* game, Config* parent) : - Canvas(parent), - m_game(game), - m_scene(new QGraphicsScene), - m_collection(new Kross::ActionCollection(QString("canvas-%1").arg(QUuid::createUuid().toString()), Kross::Manager::self().actionCollection())) -{ -} - -QGSCanvas::~QGSCanvas() -{ - delete m_scene; - delete m_collection; -} - -QString QGSCanvas::name() -{ - return "QGraphicsScene canvas"; -} - -QString QGSCanvas::description() -{ - return "A canvas using QGraphicsScene"; -} - -QIcon QGSCanvas::icon() -{ - return KIcon(); -} - -void QGSCanvas::addSprite(const QString& name, const QString& sprite, const int x, const int y, const int zOrder) -{ - // TODO: NOOP or refresh? - if (m_items.contains(name)) - return; - SpriteWrapper* spr = m_game->sprite(sprite); - if (spr) - { - QGraphicsPixmapItem* item = new QGraphicsPixmapItem(spr->sprite()); - item->setPos(x, y); - item->setZValue(zOrder); - m_scene->addItem(item); - m_items[name] = item; - } -} - -void QGSCanvas::removeSprite(const QString& name) -{ - if (m_items.contains(name)) - { - delete m_items[name]; - m_items.remove(name); - } -} - -void QGSCanvas::transform(const QString& transform, const QString& object, const QVariantList& parameters) -{ -} - -int QGSCanvas::type() const -{ - return QGraphicsSceneCanvas; -} - -QWidget* QGSCanvas::viewport() -{ - // TODO: Only one view allowed? or as many as wanted? - QGraphicsView* view = new QGraphicsView; - view->setScene(m_scene); - return view; -} diff --git a/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.h b/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.h deleted file mode 100644 index d779a3b3..00000000 --- a/plugins/sigen_canvas_standard/qgraphicsscene/QGSCanvas.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2009 Ben Boeckel - * - * 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 . - */ - -#ifndef SIGENCANVASES_QGSCANVAS -#define SIGENCANVASES_QGSCANVAS - -// Sigencore includes -#include - -// Forward declarations -namespace Kross -{ -class ActionCollection; -} -class QGraphicsItem; -class QGraphicsScene; -namespace Sigscript -{ -class GameWrapper; -} - -class QGSCanvas : public Sigencore::Canvas -{ - Q_OBJECT - - public: - QGSCanvas(Sigscript::GameWrapper* game, Sigscript::Config* parent); - ~QGSCanvas(); - - static QString name(); - static QString description(); - static QIcon icon(); - - Q_SCRIPTABLE void addSprite(const QString& name, const QString& sprite, const int x, const int y, const int zOrder); - Q_SCRIPTABLE void removeSprite(const QString& name); - Q_SCRIPTABLE void transform(const QString& transform, const QString& object, const QVariantList& parameters); - - int type() const; - - QWidget* viewport(); - private: - Sigscript::GameWrapper* m_game; - QGraphicsScene* m_scene; - QMap m_items; - Kross::ActionCollection* m_collection; -}; - -#endif diff --git a/plugins/sigen_canvas_standard/sigen_canvases.desktop b/plugins/sigen_canvas_standard/sigen_canvases.desktop deleted file mode 100644 index 7731030c..00000000 --- a/plugins/sigen_canvas_standard/sigen_canvases.desktop +++ /dev/null @@ -1,16 +0,0 @@ -[Desktop Entry] -Type=Service -X-KDE-ServiceTypes=Sigen/Canvas -Icon=sigen-canvasplugin -Name=Sigen Canvases -X-Sigen-MinVersion=0.1.1 -X-KDE-Library=canvas_sigen -X-KDE-PluginInfo-Author=Ben Boeckel -X-KDE-PluginInfo-Email=MathStuf@gmail.com -X-KDE-PluginInfo-Name=sigen_canvas -X-KDE-PluginInfo-Version=0.1.1 -X-KDE-PluginInfo-Website= -X-KDE-PluginInfo-Category=canvas -X-KDE-PluginInfo-Depends= -X-KDE-PluginInfo-License=GPLv3 -X-KDE-PluginInfo-EnabledByDefault=true -- cgit