diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2009-04-01 02:15:35 -0400 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2009-04-01 02:15:35 -0400 |
commit | ea97b53e8e934f54a646f52eff94fea5316160f2 (patch) | |
tree | 856b841fa23182d0c5a7eb8f20a72144b7860f8b | |
parent | 11fb74db1d0095e9f61d4c6106182f48310babb7 (diff) | |
download | sigen-ea97b53e8e934f54a646f52eff94fea5316160f2.tar.gz sigen-ea97b53e8e934f54a646f52eff94fea5316160f2.tar.xz sigen-ea97b53e8e934f54a646f52eff94fea5316160f2.zip |
Add mapPosition storage to Game
-rw-r--r-- | sigmod/Game.cpp | 37 | ||||
-rw-r--r-- | sigmod/Game.h | 7 | ||||
-rw-r--r-- | sigscript/GameWrapper.cpp | 5 | ||||
-rw-r--r-- | sigscript/GameWrapper.h | 4 |
4 files changed, 53 insertions, 0 deletions
diff --git a/sigmod/Game.cpp b/sigmod/Game.cpp index e66955a6..3ee95120 100644 --- a/sigmod/Game.cpp +++ b/sigmod/Game.cpp @@ -91,6 +91,7 @@ void Game::validate() emit(error("Version is empty")); if (m_description.isEmpty()) emit(warning("Description is empty")); + // TODO: check map positioning if ((m_typechart.width() != typeCount()) || (m_typechart.height() != typeCount())) emit(error("Type chart is invalid")); TEST_CHILD(m_rules); @@ -301,6 +302,7 @@ void Game::load(const QDomElement& xml) LOAD_SUB(newTrainer, Trainer); LOAD_SUB(newType, Type); LOAD_SUB(newWeather, Weather); + LOAD_MAP(mapPosition, position); LOAD_MATRIX(typechart); m_typechart.resize(typeCount(), typeCount()); } @@ -315,6 +317,7 @@ QDomElement Game::save() const SAVE(singlePlayer); SAVE(startScript); SAVE_Rules(rules); + SAVE_MAP(mapPosition, position); SAVE_MATRIX(typechart); SAVE_SUB(Ability, abilities); SAVE_SUB(Author, authors); @@ -346,6 +349,26 @@ SETTER(Game, QString&, Version, version) SETTER(Game, QString&, Description, description) SETTER(Game, bool, SinglePlayer, singlePlayer) SETTER(Game, Script&, StartScript, startScript) + +void Game::setMapPosition(const int map, const QPoint& position, const bool remove) +{ + if (remove) + { + if (m_mapPosition.contains(map)) + { + m_mapPosition.remove(map); + emit(changed()); + } + } + else if (!mapById(map)) + EBOUNDS_IDX(map); + else if (!m_mapPosition.contains(map) || (position != m_mapPosition[map])) + { + m_mapPosition[map] = position; + emit(changed()); + } +} + SETTER_MATRIX(Game, Fraction&, Typechart, typechart, multiplier) void Game::setRules(const Rules& rules) @@ -379,6 +402,18 @@ Fraction Game::typechart(const int attack, const int defense) const return m_typechart(attack, defense); } +QPoint Game::mapPosition(const int map) const +{ + if (m_mapPosition.contains(map)) + return m_mapPosition[map]; + return QPoint(); +} + +QMap<int, QPoint> Game::mapPosition() const +{ + return m_mapPosition; +} + const Rules* Game::rules() const { return m_rules; @@ -395,6 +430,7 @@ CHECK(Game, QString&, description) CHECK(Game, bool, singlePlayer) CHECK(Game, Script&, startScript) CHECK_BOUNDS(Game, Fraction&, typechart, 0, INT_MAX) +CHECK(Game, QPoint&, mapPosition) SSUBCLASS(Game, Ability, ability, abilities) SSUBCLASS(Game, Author, author, authors) @@ -513,6 +549,7 @@ Game& Game::operator=(const Game& rhs) COPY(description); COPY(singlePlayer); COPY(startScript); + COPY(mapPosition); COPY(typechart); COPY_Rules(rules); COPY_SUB(Ability, abilities); diff --git a/sigmod/Game.h b/sigmod/Game.h index 1d39a02e..68b2317e 100644 --- a/sigmod/Game.h +++ b/sigmod/Game.h @@ -32,6 +32,8 @@ // Qt includes #include <QtCore/QList> +#include <QtCore/QMap> +#include <QtCore/QPoint> namespace Sigmod { @@ -119,6 +121,7 @@ class SIGMOD_EXPORT Game : public Object void setSinglePlayer(const bool singlePlayer); void setStartScript(const Sigcore::Script& startScript); void setTypechart(const int attack, const int defense, const Sigcore::Fraction& multiplier); + void setMapPosition(const int map, const QPoint& position, const bool remove = false); void setRules(const Rules& rules); void setRules(const QDomElement& xml); @@ -130,6 +133,8 @@ class SIGMOD_EXPORT Game : public Object const Sigcore::Matrix<Sigcore::Fraction>* typechart() const; Sigcore::Matrix<Sigcore::Fraction>* typechart(); Sigcore::Fraction typechart(const int attack, const int defense) const; + QPoint mapPosition(const int map) const; + QMap<int, QPoint> mapPosition() const; const Rules* rules() const; Rules* rules(); @@ -138,6 +143,7 @@ class SIGMOD_EXPORT Game : public Object bool descriptionCheck(const QString& description) const; bool singlePlayerCheck(const bool singlePlayer) const; bool startScriptCheck(const Sigcore::Script& startScript) const; + bool mapPositionCheck(const QPoint& position) const; bool typechartCheck(const Sigcore::Fraction& multiplier) const; const Ability* ability(const int index) const; @@ -480,6 +486,7 @@ class SIGMOD_EXPORT Game : public Object bool m_singlePlayer; Sigcore::Script m_startScript; Sigcore::Matrix<Sigcore::Fraction> m_typechart; + QMap<int, QPoint> m_mapPosition; Rules* m_rules; QList<Ability*> m_abilities; QList<Author*> m_authors; diff --git a/sigscript/GameWrapper.cpp b/sigscript/GameWrapper.cpp index d93aee86..82355b44 100644 --- a/sigscript/GameWrapper.cpp +++ b/sigscript/GameWrapper.cpp @@ -263,6 +263,11 @@ Fraction GameWrapper::effectiveness(const TypeWrapper* attacker, const TypeWrapp return m_game->typechart(m_game->typeIndex(attacker->id()), m_game->typeIndex(defender->id())); } +QPoint GameWrapper::mapPosition(const MapWrapper* map) const +{ + return m_game->mapPosition(map->id()); +} + RulesWrapper* GameWrapper::rules() { return RulesWrapper::create(m_game->rules(), this); diff --git a/sigscript/GameWrapper.h b/sigscript/GameWrapper.h index 179d77f8..efff7de3 100644 --- a/sigscript/GameWrapper.h +++ b/sigscript/GameWrapper.h @@ -29,6 +29,9 @@ #include <sigmod/Direction.h> #include <sigmod/Stat.h> +// Qt includes +#include <QtCore/QPoint> + // Forward declarations namespace Sigmod { @@ -103,6 +106,7 @@ class SIGSCRIPT_EXPORT GameWrapper : public ObjectWrapper Q_SCRIPTABLE bool singlePlayer() const; Q_SCRIPTABLE Sigcore::Script startScript(); Q_SCRIPTABLE Sigcore::Fraction effectiveness(const TypeWrapper* attacker, const TypeWrapper* defender) const; + Q_SCRIPTABLE QPoint mapPosition(const MapWrapper* map) const; Q_SCRIPTABLE RulesWrapper* rules(); Q_SCRIPTABLE AbilityWrapper* ability(const QString& name); |