diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-11-08 06:15:08 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-11-08 06:15:08 +0000 |
| commit | 8bad37e82371bd41864903ac0d6f49808ad119bf (patch) | |
| tree | 77f0cb46059654cefb357d6eb4064c5740edf3d4 /sigscript | |
| parent | c127c0dae65a7600e0ab30b634f25d4915c61d16 (diff) | |
[FIX] No more asserts in sigmod
[FIX] Moved to using *ById instead of *Index methods in sigmod
[FIX] Tilemaps are now collaged (not completely done on the editing side yet)
[FIX] Removed the resource files (drawn natively instead)
[FIX] ATBTimer now uses the built-in QTimer in a QObject
[FIX] Coordinates are now edited on the map for warps, trainers, and effects
[FIX] Tiles are now completely scripted
[FIX] Config is now thread-safe
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@308 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'sigscript')
| -rw-r--r-- | sigscript/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | sigscript/Config.cpp | 11 | ||||
| -rw-r--r-- | sigscript/Config.h | 4 | ||||
| -rw-r--r-- | sigscript/MapTileWrapper.cpp | 56 | ||||
| -rw-r--r-- | sigscript/MapTileWrapper.h | 52 | ||||
| -rw-r--r-- | sigscript/MapWarpWrapper.cpp | 8 | ||||
| -rw-r--r-- | sigscript/MapWarpWrapper.h | 2 | ||||
| -rw-r--r-- | sigscript/MapWrapper.cpp | 23 | ||||
| -rw-r--r-- | sigscript/MapWrapper.h | 6 | ||||
| -rw-r--r-- | sigscript/TileWrapper.cpp | 19 | ||||
| -rw-r--r-- | sigscript/TileWrapper.h | 5 |
11 files changed, 155 insertions, 33 deletions
diff --git a/sigscript/CMakeLists.txt b/sigscript/CMakeLists.txt index bbfcd8b4..32185aa8 100644 --- a/sigscript/CMakeLists.txt +++ b/sigscript/CMakeLists.txt @@ -17,6 +17,7 @@ SET(sigscript_HEADERS ItemTypeWrapper.h MapWrapper.h MapEffectWrapper.h + MapTileWrapper.h MapTrainerWrapper.h MapTrainerTeamMemberWrapper.h MapWarpWrapper.h @@ -55,6 +56,7 @@ SET(sigscript_SRCS ItemTypeWrapper.cpp MapWrapper.cpp MapEffectWrapper.cpp + MapTileWrapper.cpp MapTrainerWrapper.cpp MapTrainerTeamMemberWrapper.cpp MapWarpWrapper.cpp diff --git a/sigscript/Config.cpp b/sigscript/Config.cpp index 0340d741..3c88728b 100644 --- a/sigscript/Config.cpp +++ b/sigscript/Config.cpp @@ -19,7 +19,8 @@ #include "Config.h" Sigscript::Config::Config(QObject* parent) : - QObject(parent) + QObject(parent), + m_lock(QReadWriteLock::Recursive) { } @@ -34,6 +35,7 @@ void Sigscript::Config::addValue(const QString& name, const QVariant& value, con void Sigscript::Config::setValue(const QString& name, const QVariant& value, const Options options) { + QWriteLocker locker(&m_lock); QVariant oldValue = m_values[name].first; m_values[name] = Value(value, options); emit(valueChanged(name, oldValue, value)); @@ -41,6 +43,7 @@ void Sigscript::Config::setValue(const QString& name, const QVariant& value, con void Sigscript::Config::setOptions(const QString& name, const Options options) { + QWriteLocker locker(&m_lock); const Options oldOptions = m_values[name].second; m_values[name].second |= options; emit(optionsChanged(name, oldOptions, options)); @@ -48,6 +51,7 @@ void Sigscript::Config::setOptions(const QString& name, const Options options) void Sigscript::Config::unsetOptions(const QString& name, const Options options) { + QWriteLocker locker(&m_lock); const Options oldOptions = m_values[name].second; m_values[name].second |= ~options; emit(optionsChanged(name, oldOptions, options)); @@ -55,6 +59,7 @@ void Sigscript::Config::unsetOptions(const QString& name, const Options options) void Sigscript::Config::removeValue(const QString& name, const bool shadow) { + QWriteLocker locker(&m_lock); if (shadow) m_values[name].second |= Deleted; else @@ -64,6 +69,7 @@ void Sigscript::Config::removeValue(const QString& name, const bool shadow) QVariant Sigscript::Config::value(const QString& name, const bool recursive) const { + QReadLocker locker(&m_lock); if (m_values.contains(name)) { if (m_values[name].second & (Deleted | Hidden)) @@ -85,6 +91,7 @@ QVariant Sigscript::Config::value(const QString& name, const bool recursive) con bool Sigscript::Config::hasValue(const QString& name, const bool recursive) const { + QReadLocker locker(&m_lock); if (m_values.contains(name)) return !(m_values[name].second & (Deleted | Hidden)); if (recursive && qobject_cast<Config*>(parent())) @@ -94,6 +101,7 @@ bool Sigscript::Config::hasValue(const QString& name, const bool recursive) cons void Sigscript::Config::clean() { + QWriteLocker locker(&m_lock); for (QMutableMapIterator<QString, Value> i(m_values); i.hasNext(); i.next()) { if (i.value().second & Temporary) @@ -107,4 +115,5 @@ void Sigscript::Config::clean() void Sigscript::Config::writeBack() { + QWriteLocker locker(&m_lock); } diff --git a/sigscript/Config.h b/sigscript/Config.h index 3ca15f84..309220c2 100644 --- a/sigscript/Config.h +++ b/sigscript/Config.h @@ -25,6 +25,7 @@ #include <QtCore/QMap> #include <QtCore/QObject> #include <QtCore/QPair> +#include <QtCore/QReadWriteLock> #include <QtCore/QString> #include <QtCore/QStringList> #include <QtCore/QVariant> @@ -76,11 +77,13 @@ class SIGSCRIPT_EXPORT Config : public QObject virtual void writeBack(); private: + mutable QReadWriteLock m_lock; QMap<QString, Value> m_values; }; template<typename T> T Config::valueOfType(const QString& name, const bool recursive) const { + QReadLocker locker(&m_lock); if (hasValueOfType<T>(name)) return m_values[name].first.value<T>(); if (recursive) @@ -98,6 +101,7 @@ template<typename T> T Config::valueOfType(const QString& name, const bool recur template<typename T> bool Config::hasValueOfType(const QString& name, const bool recursive) const { + QReadLocker locker(&m_lock); if (hasValue(name) && m_values[name].first.canConvert<T>()) return true; if (recursive && qobject_cast<Config*>(parent())) diff --git a/sigscript/MapTileWrapper.cpp b/sigscript/MapTileWrapper.cpp new file mode 100644 index 00000000..2ca2abbe --- /dev/null +++ b/sigscript/MapTileWrapper.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2008 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 "MapTileWrapper.h" + +// Sigscript includes +#include "MapWrapper.h" +#include "SigmodWrapper.h" + +Sigscript::MapTileWrapper* Sigscript::MapTileWrapper::create(const Sigmod::MapTile* tile, MapWrapper* parent) +{ + Signature sig = Signature(parent, Subsignature(tile->className(), tile->id())); + if (!m_instances.contains(sig)) + m_instances[sig] = new MapTileWrapper(tile, parent); + return qobject_cast<MapTileWrapper*>(m_instances[sig]); +} + +Sigscript::MapTileWrapper::MapTileWrapper(const Sigmod::MapTile* tile, MapWrapper* parent) : + ObjectWrapper(tile, parent), + m_tile(tile) +{ +} + +Sigscript::TileWrapper* Sigscript::MapTileWrapper::tile() +{ + return sigmod()->tile(m_tile->tile()); +} + +QPoint Sigscript::MapTileWrapper::position() const +{ + if (sigmod()->singlePlayer() && hasValueOfType<QPoint>("position")) + return valueOfType<QPoint>("position"); + return m_tile->position(); +} + +int Sigscript::MapTileWrapper::zIndex() const +{ + if (sigmod()->singlePlayer() && hasValueOfType<int>("zIndex")) + return valueOfType<int>("zIndex"); + return m_tile->zIndex(); +} diff --git a/sigscript/MapTileWrapper.h b/sigscript/MapTileWrapper.h new file mode 100644 index 00000000..26dbcf09 --- /dev/null +++ b/sigscript/MapTileWrapper.h @@ -0,0 +1,52 @@ +/* + * Copyright 2008 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/>. + */ + +#ifndef SIGSCRIPT_MAPTILEWRAPPER +#define SIGSCRIPT_MAPTILEWRAPPER + +// Sigscript includes +#include "ObjectWrapper.h" + +// Sigmod includes +#include "../sigmod/MapTile.h" + +namespace Sigscript +{ +// Forward declarations +class MapWrapper; +class TileWrapper; + +class SIGSCRIPT_EXPORT MapTileWrapper : public ObjectWrapper +{ + Q_OBJECT + + public: + static MapTileWrapper* create(const Sigmod::MapTile* tile, MapWrapper* parent); + + Q_SCRIPTABLE TileWrapper* tile(); + Q_SCRIPTABLE QPoint position() const; + Q_SCRIPTABLE int zIndex() const; + private: + MapTileWrapper(const Sigmod::MapTile* tile, MapWrapper* parent); + MapTileWrapper& operator=(const MapTileWrapper& rhs); + + const Sigmod::MapTile* m_tile; +}; +} +Q_DECLARE_METATYPE(Sigscript::MapTileWrapper*) + +#endif diff --git a/sigscript/MapWarpWrapper.cpp b/sigscript/MapWarpWrapper.cpp index dfa581c6..4af106a9 100644 --- a/sigscript/MapWarpWrapper.cpp +++ b/sigscript/MapWarpWrapper.cpp @@ -54,11 +54,11 @@ QString Sigscript::MapWarpWrapper::name() const return m_warp->name(); } -QPoint Sigscript::MapWarpWrapper::coordinate() const +QRect Sigscript::MapWarpWrapper::area() const { - if (sigmod()->singlePlayer() && hasValueOfType<QPoint>("coordinate")) - return valueOfType<QPoint>("coordinate"); - return m_warp->coordinate(); + if (sigmod()->singlePlayer() && hasValueOfType<QRect>("area")) + return valueOfType<QRect>("area"); + return m_warp->area(); } Sigmod::MapWarp::Type Sigscript::MapWarpWrapper::type() const diff --git a/sigscript/MapWarpWrapper.h b/sigscript/MapWarpWrapper.h index f1c3f9e9..14c5cb81 100644 --- a/sigscript/MapWarpWrapper.h +++ b/sigscript/MapWarpWrapper.h @@ -39,7 +39,7 @@ class SIGSCRIPT_EXPORT MapWarpWrapper : public ObjectWrapper Q_SCRIPTABLE Sigmod::MapWarp::Type type(const QString& name) const; Q_SCRIPTABLE QString name() const; - Q_SCRIPTABLE QPoint coordinate() const; + Q_SCRIPTABLE QRect area() const; Q_SCRIPTABLE Sigmod::MapWarp::Type type() const; Q_SCRIPTABLE MapWarpWrapper* toWarp(); Q_SCRIPTABLE Sigcore::Script script() const; diff --git a/sigscript/MapWrapper.cpp b/sigscript/MapWrapper.cpp index 09167f68..30e2a6d3 100644 --- a/sigscript/MapWrapper.cpp +++ b/sigscript/MapWrapper.cpp @@ -20,6 +20,7 @@ // Sigscript includes #include "MapEffectWrapper.h" +#include "MapTileWrapper.h" #include "MapTrainerWrapper.h" #include "MapWarpWrapper.h" #include "MapWildListWrapper.h" @@ -44,6 +45,11 @@ Sigscript::MapEffectWrapper* Sigscript::MapWrapper::effect(const int id) return MapEffectWrapper::create(m_map->effectById(id), this); } +Sigscript::MapTileWrapper* Sigscript::MapWrapper::tile(const int id) +{ + return MapTileWrapper::create(m_map->tileById(id), this); +} + Sigscript::MapTrainerWrapper* Sigscript::MapWrapper::trainer(const int id) { return MapTrainerWrapper::create(m_map->trainerById(id), this); @@ -85,9 +91,14 @@ Sigmod::Map::Type Sigscript::MapWrapper::type() const return m_map->type(); } -Sigscript::TileWrapper* Sigscript::MapWrapper::tile(const int row, const int column) +int Sigscript::MapWrapper::width() const { - return sigmod()->tile(m_map->tile(row, column)); + return m_map->width(); +} + +int Sigscript::MapWrapper::height() const +{ + return m_map->height(); } Sigscript::MapEffectWrapper* Sigscript::MapWrapper::effect(const QString& name) @@ -100,6 +111,14 @@ Sigscript::MapEffectWrapper* Sigscript::MapWrapper::effect(const QString& name) return NULL; } +QList<Sigscript::MapTileWrapper*> Sigscript::MapWrapper::tiles() +{ + QList<MapTileWrapper*> tiles; + for (int i = 0; i < m_map->tileCount(); ++i) + tiles.append(MapTileWrapper::create(m_map->tile(i), this)); + return tiles; +} + Sigscript::MapTrainerWrapper* Sigscript::MapWrapper::trainer(const QString& name) { for (int i = 0; i < m_map->trainerCount(); ++i) diff --git a/sigscript/MapWrapper.h b/sigscript/MapWrapper.h index 029109cc..b6cdaae5 100644 --- a/sigscript/MapWrapper.h +++ b/sigscript/MapWrapper.h @@ -28,6 +28,7 @@ namespace Sigscript { // Forward declarations class MapEffectWrapper; +class MapTileWrapper; class MapTrainerWrapper; class MapWarpWrapper; class MapWildListWrapper; @@ -41,6 +42,7 @@ class SIGSCRIPT_EXPORT MapWrapper : public ObjectWrapper static MapWrapper* create(const Sigmod::Map* map, SigmodWrapper* parent); MapEffectWrapper* effect(const int id); + MapTileWrapper* tile(const int id); MapTrainerWrapper* trainer(const int id); MapWarpWrapper* warp(const int id); MapWildListWrapper* wildList(const int id); @@ -50,9 +52,11 @@ class SIGSCRIPT_EXPORT MapWrapper : public ObjectWrapper Q_SCRIPTABLE QString name() const; Q_SCRIPTABLE MapWarpWrapper* flyWarp(); Q_SCRIPTABLE Sigmod::Map::Type type() const; - Q_SCRIPTABLE TileWrapper* tile(const int row, const int column); + Q_SCRIPTABLE int width() const; + Q_SCRIPTABLE int height() const; Q_SCRIPTABLE MapEffectWrapper* effect(const QString& name); + Q_SCRIPTABLE QList<MapTileWrapper*> tiles(); Q_SCRIPTABLE MapTrainerWrapper* trainer(const QString& name); Q_SCRIPTABLE MapWarpWrapper* warp(const QString& name); Q_SCRIPTABLE MapWildListWrapper* wildList(const QString& name); diff --git a/sigscript/TileWrapper.cpp b/sigscript/TileWrapper.cpp index 37c10601..720824fa 100644 --- a/sigscript/TileWrapper.cpp +++ b/sigscript/TileWrapper.cpp @@ -20,7 +20,6 @@ // Sigscript includes #include "SigmodWrapper.h" -#include "SpriteWrapper.h" Sigscript::TileWrapper* Sigscript::TileWrapper::create(const Sigmod::Tile* tile, SigmodWrapper* parent) { @@ -41,24 +40,6 @@ QString Sigscript::TileWrapper::name() const return m_tile->name(); } -Sigscript::SpriteWrapper* Sigscript::TileWrapper::sprite() -{ - if (sigmod()->singlePlayer() && hasValueOfType<QString>("sprite")) - { - SpriteWrapper* sprite = sigmod()->sprite(valueOfType<QString>("sprite")); - if (sprite && sprite->sprite().size() == QSize(64, 64)) - return sprite; - } - return sigmod()->sprite(m_tile->sprite()); -} - -bool Sigscript::TileWrapper::from(const Sigmod::Direction direction) const -{ - if (sigmod()->singlePlayer() && hasValueOfType<bool>(QString("direction-%1").arg(direction))) - return valueOfType<bool>(QString("direction-%1").arg(direction)); - return m_tile->from(direction); -} - Sigcore::Script Sigscript::TileWrapper::script() const { return m_tile->script(); diff --git a/sigscript/TileWrapper.h b/sigscript/TileWrapper.h index 26d03957..ef082ce8 100644 --- a/sigscript/TileWrapper.h +++ b/sigscript/TileWrapper.h @@ -26,9 +26,6 @@ namespace Sigscript { -// Forward declarations -class SpriteWrapper; - class SIGSCRIPT_EXPORT TileWrapper : public ObjectWrapper { Q_OBJECT @@ -37,8 +34,6 @@ class SIGSCRIPT_EXPORT TileWrapper : public ObjectWrapper static TileWrapper* create(const Sigmod::Tile* tile, SigmodWrapper* parent); Q_SCRIPTABLE QString name() const; - Q_SCRIPTABLE SpriteWrapper* sprite(); - Q_SCRIPTABLE bool from(const Sigmod::Direction direction) const; Q_SCRIPTABLE Sigcore::Script script() const; private: TileWrapper(const Sigmod::Tile* tile, SigmodWrapper* parent); |
