summaryrefslogtreecommitdiffstats
path: root/sigmod
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-10-06 18:10:45 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-10-06 18:10:45 +0000
commit3a096bed018254f9d662f9ae85792b8ae5df4837 (patch)
treeb7504fd5a332a220a3ce73d035496d562545f50e /sigmod
parent2c0a3866e09140d8d5ff84178decddc22db15778 (diff)
downloadsigen-3a096bed018254f9d662f9ae85792b8ae5df4837.tar.gz
sigen-3a096bed018254f9d662f9ae85792b8ae5df4837.tar.xz
sigen-3a096bed018254f9d662f9ae85792b8ae5df4837.zip
[FIX] Started documenting Sigmod
[FIX] A few minor bugs git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@272 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'sigmod')
-rw-r--r--sigmod/Badge.h58
-rw-r--r--sigmod/Fraction.cpp4
-rw-r--r--sigmod/Fraction.h58
-rw-r--r--sigmod/Global.h33
-rw-r--r--sigmod/Hat.h70
-rw-r--r--sigmod/Macros.h7
-rw-r--r--sigmod/Map.cpp9
-rw-r--r--sigmod/Map.h1
-rw-r--r--sigmod/Matrix.h153
-rw-r--r--sigmod/Object.cpp29
-rw-r--r--sigmod/Object.h100
-rw-r--r--sigmod/Script.h53
-rw-r--r--sigmod/Sigmod.h46
13 files changed, 518 insertions, 103 deletions
diff --git a/sigmod/Badge.h b/sigmod/Badge.h
index debe7abe..e6a54ff0 100644
--- a/sigmod/Badge.h
+++ b/sigmod/Badge.h
@@ -36,7 +36,7 @@ class Sigmod;
* \brief Class describing a badge.
*
* Badges are used to show a trainer's worthiness. Without them, team members that are too high leveled may not
- * listen to its trainer. Some badges also boost stats (only with in-game battles).
+ * listen to its trainer. Badges may also boost stats.
*/
class SIGMOD_EXPORT Badge : public Object
{
@@ -59,7 +59,7 @@ class SIGMOD_EXPORT Badge : public Object
/**
* Data copy constructor. Copies the data from \p badge and parents the new badge with \p parent and id \p id.
*
- * \param ability The badge to copy the data from.
+ * \param badge The badge to copy the data from.
* \param parent The parent of the badge.
* \param id The id number for the badge.
*/
@@ -91,16 +91,70 @@ class SIGMOD_EXPORT Badge : public Object
*/
QDomElement save() const;
+ /**
+ * Sets the name of the badge to be used in the game.
+ *
+ * \param name The name of the badge.
+ */
void setName(const QString& name);
+ /**
+ * Set the \p id of the sprite that is to be used for the badge before it is obtained.
+ *
+ * \param face The \p id of the sprite to be used before the badge is obtained.
+ */
void setFace(const int face);
+ /**
+ * Set the \p id of the sprite that is to be used for the badge once it is obtained.
+ *
+ * \param badge The \p id of the sprite to be used after the badge is obtained.
+ */
void setBadge(const int badge);
+ /**
+ * Set the maximum level at which team members of the player are guaranteed to obey the player.
+ * Above this level, team members may not obey its trainer.
+ *
+ * \param obey The maximum level that is guaranteed to obey the player once the badge is obtained.
+ */
void setObey(const int obey);
+ /**
+ * Set a multiplier for a stat once the badge is obtained.
+ *
+ * \param stat The stat to set the multiplier for.
+ * \param multiplier The multiplier for the stat once the badge is obtained.
+ */
void setStat(const Stat stat, const Fraction& multiplier);
+ /**
+ * \sa setName
+ *
+ * \return The name of the badge.
+ */
QString name() const;
+ /**
+ * \sa setFace
+ *
+ * \return The \p id of the sprite that represents the badge before it is obtained.
+ */
int face() const;
+ /**
+ * \sa setBadge
+ *
+ * \return The \p id of the sprite that represents the badge once it has been obtained.
+ */
int badge() const;
+ /**
+ * \sa setObey
+ *
+ * \return The maximum level that is guaranteed to obey the player once the badge is obtained.
+ */
int obey() const;
+ /**
+ * \sa setStat
+ *
+ * \param stat The stat to get the multiplier for.
+ *
+ * \return The multiplier for the \p stat.
+ */
Fraction stat(const Stat stat) const;
Badge& operator=(const Badge& rhs);
diff --git a/sigmod/Fraction.cpp b/sigmod/Fraction.cpp
index f3f1ecd7..8bafe022 100644
--- a/sigmod/Fraction.cpp
+++ b/sigmod/Fraction.cpp
@@ -15,6 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file sigmod/Fraction.cpp
+ */
+
// Header include
#include "Fraction.h"
diff --git a/sigmod/Fraction.h b/sigmod/Fraction.h
index b2315fc3..65f59523 100644
--- a/sigmod/Fraction.h
+++ b/sigmod/Fraction.h
@@ -15,6 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file sigmod/Fraction.h
+ */
+
#ifndef SIGMOD_FRACTION
#define SIGMOD_FRACTION
@@ -26,21 +30,75 @@
namespace Sigmod
{
+/**
+ * \class Sigmod::Fraction Fraction.h sigmod/Fraction.h
+ * \brief Class that represents a fractional quantity.
+ *
+ * This class should be used in place of \p double because of accuracy.
+ */
class SIGMOD_EXPORT Fraction
{
public:
+ /**
+ * Constructor.
+ *
+ * \param numerator The numerator of the fraction.
+ * \param denominator The denominator of the fraction.
+ */
explicit Fraction(const int numerator = 1, const int denominator = 1);
+ /**
+ * Copy constructor.
+ *
+ * \param fraction The value to copy.
+ */
Fraction(const Fraction& fraction);
+ /**
+ * Set the value of the fraction.
+ *
+ * \param numerator The numerator of the fraction.
+ * \param denominator The denominator of the fraction.
+ */
void set(const int numerator, const int denominator);
+ /**
+ * Sets the numerator of the fraction.
+ *
+ * \param numerator The numerator of the fraction.
+ */
void setNumerator(const int numerator);
+ /**
+ * Set the denominator of the fraciton.
+ *
+ * \param denominator The denominator of the fraction.
+ */
void setDenominator(const int denominator);
+ /**
+ * \return The numerator of the fraction.
+ */
int numerator() const;
+ /**
+ * \return The denominator of the fraction.
+ */
int denominator() const;
+ /**
+ * Reduces the fraction.
+ */
void reduce();
+ /**
+ * Uses the value of the fraction to return a weighted boolean.
+ *
+ * \return \p true with a weight of the fraction, \p false otherwise.
+ */
bool poll() const;
+ /**
+ * Convenience function to get a weighted boolean value.
+ *
+ * \param numerator The numerator of the chance that the function returns \p true.
+ * \param demoninator The denominator of the chance that the function returns \p true.
+ * \return \p true with a weight of the (\p numerator / \p denominator), \p false otherwise.
+ */
static bool poll(const int numerator, const int demoninator);
Fraction& operator=(const Fraction& rhs);
diff --git a/sigmod/Global.h b/sigmod/Global.h
index ea75387a..a7fdd8e1 100644
--- a/sigmod/Global.h
+++ b/sigmod/Global.h
@@ -15,6 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file sigmod/Global.h
+ */
+
#ifndef SIGMOD_GLOBAL
#define SIGMOD_GLOBAL
@@ -26,21 +30,23 @@
#include <kdemacros.h>
#ifndef SIGMOD_EXPORT
-# ifdef MAKE_SIGMOD_LIB
- /* We are building this library */
-# define SIGMOD_EXPORT KDE_EXPORT
-# else
- /* We are using this library */
-# define SIGMOD_EXPORT KDE_IMPORT
-# endif
+# ifdef MAKE_SIGMOD_LIB
+# define SIGMOD_EXPORT KDE_EXPORT /// Export the symbol if building the library.
+# else
+# define SIGMOD_EXPORT KDE_IMPORT /// Import the symbol if including the library.
+# endif
#endif
-# ifndef SIGMOD_EXPORT_DEPRECATED
-# define SIGMOD_EXPORT_DEPRECATED KDE_DEPRECATED SIGMOD_EXPORT
-# endif
+#ifndef SIGMOD_EXPORT_DEPRECATED
+# define SIGMOD_EXPORT_DEPRECATED KDE_DEPRECATED SIGMOD_EXPORT /// Mark as deprecated
+#endif
namespace Sigmod
{
+/**
+ * \enum Stat
+ * \brief Enumeration of stats.
+ */
enum Stat
{
ST_HP = 0,
@@ -53,9 +59,15 @@ enum Stat
ST_Accuracy = 6,
ST_Evasion = 7,
};
+/// Strings for the stats for a combined Special stat.
const QStringList StatRBYStr = QStringList() << "HP" << "Attack" << "Defense" << "Speed" << "Special" << "" << "Accuracy" << "Evasion";
+/// Strings for the stats when the Special stat is split.
const QStringList StatGSCStr = QStringList() << "HP" << "Attack" << "Defense" << "Speed" << "Special Attack" << "Special Defense" << "Accuracy" << "Evasion";
+/**
+ * \enum Direction
+ * \brief Enumeration of directions.
+ */
enum Direction
{
D_Up = 0,
@@ -64,6 +76,7 @@ enum Direction
D_Right = 3,
D_None = 4
};
+/// Strings for the directions.
const QStringList DirectionStr = QStringList() << "Up" << "Down" << "Left" << "Right" << "None";
}
diff --git a/sigmod/Hat.h b/sigmod/Hat.h
index c9ae94f0..20514412 100644
--- a/sigmod/Hat.h
+++ b/sigmod/Hat.h
@@ -15,10 +15,15 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file sigmod/Hat.h
+ */
+
#ifndef SIGMOD_HAT
#define SIGMOD_HAT
// Sigmod includes
+#include "Fraction.h"
#include "Global.h"
// Qt includes
@@ -27,22 +32,72 @@
namespace Sigmod
{
+/**
+ * \class Sigmod::Hat Hat.h sigmod/Hat.h
+ * \brief Class to help choose items from a weighted set of items.
+ *
+ * Given a set of weighted items to choose from, Hat will pick out a random item from the set.
+ */
template<class T> class Hat
{
public:
+ /**
+ * Default constructor.
+ */
Hat();
+ /**
+ * Choose an item from the set without removal.
+ *
+ * \return The item chosen.
+ */
T pick() const;
+ /**
+ * Choose an item from the set with removal.
+ *
+ * \return The item chosen.
+ */
T take();
+ /**
+ * Choose an item from the set as well as all identical items.
+ *
+ * \return The item chosen.
+ */
T takeAndClear();
+ /**
+ * Set the weight of an item in the set.
+ *
+ * \param key The item to set.
+ * \param weight The weight of the item.
+ */
void setCount(const T& key, const int weight);
+ /**
+ * Add a number of items to the set.
+ *
+ * \param key The item to add to the set.
+ * \param weight How many of the item to add.
+ */
void add(const T& key, const int weight);
+ /**
+ * \return The number of distinct items in the set.
+ */
int distinctCount() const;
+ /**
+ * \return The number of total items in the set.
+ */
int count() const;
+ /**
+ * \param key The item to get the count of.
+ *
+ * \return The amount of \p key in the set.
+ */
int count(const T& key) const;
- double chance(const T& key) const;
-
- int operator[](const T& key) const;
+ /**
+ * \param key The item to get the chance of.
+ *
+ * \return The chance of choosing \p key.
+ */
+ Fraction chance(const T& key) const;
private:
QMap<T, int> m_objects;
int m_count;
@@ -119,14 +174,9 @@ template<class T> inline int Hat<T>::count(const T& key) const
return 0;
}
-template<class T> inline double Hat<T>::chance(const T& key) const
-{
- return (double(count(key)) / m_count);
-}
-
-template<class T> inline int Hat<T>::operator[](const T& key) const
+template<class T> inline Fraction Hat<T>::chance(const T& key) const
{
- return count(key);
+ return Fraction(count(key), m_count);
}
}
diff --git a/sigmod/Macros.h b/sigmod/Macros.h
index 6d61526a..dd149746 100644
--- a/sigmod/Macros.h
+++ b/sigmod/Macros.h
@@ -15,13 +15,16 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file sigmod/Macros.h
+ * \todo Replace macros with protected methods of Object
+ */
+
#ifndef SIGMOD_MACROS
#define SIGMOD_MACROS
#ifdef MAKE_SIGMOD_LIB
-// TODO: The macros should probably be replaced by protected members of Object
-
#define LOAD_ID() \
int newId = id; \
if ((id == -1) && xml.hasAttribute("id")) \
diff --git a/sigmod/Map.cpp b/sigmod/Map.cpp
index fe599cc6..021de6ac 100644
--- a/sigmod/Map.cpp
+++ b/sigmod/Map.cpp
@@ -169,7 +169,7 @@ void Sigmod::Map::setTile(const int row, const int column, const int tile)
if (qobject_cast<const Sigmod*>(sigmod())->tileIndex(tile) == INT_MAX)
emit(error(bounds("tile")));
else
- m_map.set(row, column, tile);
+ m_map(row, column) = tile;
}
void Sigmod::Map::insertColumn(const int column)
@@ -214,7 +214,7 @@ Sigmod::Matrix<int>* Sigmod::Map::map()
int Sigmod::Map::tile(const int row, const int column) const
{
- return m_map.at(row, column);
+ return m_map(row, column);
}
int Sigmod::Map::width() const
@@ -227,11 +227,6 @@ int Sigmod::Map::height() const
return m_map.height();
}
-QPoint Sigmod::Map::size() const
-{
- return m_map.size();
-}
-
const Sigmod::MapEffect* Sigmod::Map::effect(const int index) const
{
Q_ASSERT(index < effectCount());
diff --git a/sigmod/Map.h b/sigmod/Map.h
index 030ce05d..4657e9dc 100644
--- a/sigmod/Map.h
+++ b/sigmod/Map.h
@@ -80,7 +80,6 @@ class SIGMOD_EXPORT Map : public Object
int tile(const int row, const int column) const;
int width() const;
int height() const;
- QPoint size() const;
const MapEffect* effect(const int index) const;
MapEffect* effect(const int index);
diff --git a/sigmod/Matrix.h b/sigmod/Matrix.h
index 37c9b58d..16d3a5d0 100644
--- a/sigmod/Matrix.h
+++ b/sigmod/Matrix.h
@@ -15,6 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file sigmod/Matrix.h
+ */
+
#ifndef SIGMOD_MATRIX
#define SIGMOD_MATRIX
@@ -27,34 +31,125 @@
namespace Sigmod
{
+/**
+ * \class Sigmod::Matrix Matrix.h sigmod/Matrix.h
+ * \brief Class for a two dimensional vector.
+ */
template<class T> class SIGMOD_EXPORT Matrix
{
public:
+ /**
+ * Default constructor.
+ */
Matrix();
+ /**
+ * Constructor.
+ *
+ * \param height The height of the matrix.
+ * \param width The width of the matrix.
+ * \param value The value to set all values to.
+ */
Matrix(const int height, const int width, const T& value = T());
+ /**
+ * Copy constructor.
+ *
+ * \param rhs The matrix to copy.
+ */
Matrix(const Matrix<T>& rhs);
+ /**
+ * Add a row to the matrix.
+ *
+ * \param value The value to set the row to.
+ */
void addRow(const T& value = T());
+ /**
+ * Add a column to the matrix.
+ *
+ * \param value The value to set the column to.
+ */
void addColumn(const T& value = T());
+ /**
+ * Inserts a row into the matrix.
+ *
+ * \param row Where the new row will be placed.
+ * \param value The value to set the row to.
+ */
void insertRow(const int row, const T& value = T());
+ /**
+ * Inserts a column into the matrix.
+ *
+ * \param column Where the new column will be placed.
+ * \param value The value to set the column to.
+ */
void insertColumn(const int column, const T& value = T());
+ /**
+ * Removes a row from the matrix.
+ *
+ * \param row The row to remove from the matrix.
+ */
void deleteRow(const int row);
+ /**
+ * Removes a column from the matrix.
+ *
+ * \param column The column to remove from the matrix.
+ */
void deleteColumn(const int column);
+ /**
+ * Clears the matrix.
+ */
void clear();
- void set(const int row, const int column, const T& value);
+ /**
+ * Resizes the matrix to a new size. Rows and columns are removed from the end to shrink and added to the
+ * end to grow.
+ *
+ * \param newHeight The target height.
+ * \param newWidth The target width.
+ * \param value Value to set any additional rows and columns to.
+ */
void resize(const int newHeight, const int newWidth, const T& value = T());
- T at(const int row, const int column) const;
+ /**
+ * Get a row from the matrix.
+ *
+ * \param row The row to retrieve.
+ * \return A row of the matrix.
+ */
QVector<T> row(const int row) const;
+ /**
+ * Get a column from the matrix.
+ *
+ * \param column The column to retrieve.
+ * \return A column of the matrix.
+ */
QVector<T> column(const int column) const;
+ /**
+ * \return The height of the matrix.
+ */
int height() const;
+ /**
+ * \return The width of the matrix.
+ */
int width() const;
- QPoint size() const;
+ /**
+ * Method for accessing values in the matrix.
+ *
+ * \param row The row of the cell.
+ * \param column The column of te cell.
+ * \return The value of the cell in the matrix.
+ */
T& operator()(const int row, const int column);
+ /**
+ * Convenience method.
+ *
+ * \param row The row of the cell.
+ * \param column The column of te cell.
+ * \return The value of the cell in the matrix.
+ */
T operator()(const int row, const int column) const;
Matrix<T>& operator=(const Matrix<T>& rhs);
bool operator==(const Matrix<T>& rhs) const;
@@ -79,41 +174,30 @@ template<class T> Matrix<T>::Matrix(const Matrix<T>& rhs)
template<class T> void Matrix<T>::addRow(const T& value)
{
- if (size() == QPoint(0, 0))
- m_matrix.append(QVector<T>(1, value));
- else
- m_matrix.append(QVector<T>(width(), value));
+ insertRow(height(), value);
}
template<class T> void Matrix<T>::addColumn(const T& value)
{
- if (size() == QPoint(0, 0))
- m_matrix.append(QVector<T>(1, value));
- else
- {
- for (int i = 0; i < height(); ++i)
- m_matrix[i].append(value);
- }
+ insertColumn(width(), value);
}
template<class T> void Matrix<T>::insertRow(const int row, const T& value)
{
- if (size() == QPoint(0, 0))
+ Q_ASSERT(row <= height());
+ if (!height() || !width())
m_matrix.append(QVector<T>(1, value));
else
- {
- Q_ASSERT(row <= height());
m_matrix.insert(row, QVector<T>(width(), value));
- }
}
template<class T> void Matrix<T>::insertColumn(const int column, const T& value)
{
- if (size() == QPoint(0, 0))
+ Q_ASSERT(column <= width());
+ if (!height() || !width())
m_matrix.append(QVector<T>(1, value));
else
{
- Q_ASSERT(column <= width());
for (int i = 0; i < height(); ++i)
m_matrix[i].insert(column, value);
}
@@ -121,22 +205,20 @@ template<class T> void Matrix<T>::insertColumn(const int column, const T& value)
template<class T> void Matrix<T>::deleteRow(const int row)
{
+ Q_ASSERT(row < height());
if (height() == 1)
m_matrix.clear();
else
- {
- Q_ASSERT(row < height());
m_matrix.remove(row);
- }
}
template<class T> void Matrix<T>::deleteColumn(const int column)
{
+ Q_ASSERT(column < width());
if (width() == 1)
m_matrix.clear();
else
{
- Q_ASSERT(column < width());
for (int i = 0; i < height(); ++i)
m_matrix[i].remove(column);
}
@@ -147,13 +229,6 @@ template<class T> void Matrix<T>::clear()
m_matrix.clear();
}
-template<class T> void Matrix<T>::set(const int row, const int column, const T& value)
-{
- Q_ASSERT(row < height());
- Q_ASSERT(column < width());
- (m_matrix[row])[column] = value;
-}
-
template<class T> void Matrix<T>::resize(const int newHeight, const int newWidth, const T& value)
{
while (height() < newHeight)
@@ -166,13 +241,6 @@ template<class T> void Matrix<T>::resize(const int newHeight, const int newWidth
deleteColumn(newWidth);
}
-template<class T> T Matrix<T>::at(const int row, const int column) const
-{
- Q_ASSERT(row < height());
- Q_ASSERT(column < width());
- return m_matrix.at(row).at(column);
-}
-
template<class T> QVector<T> Matrix<T>::row(const int row) const
{
Q_ASSERT(row < height());
@@ -200,11 +268,6 @@ template<class T> int Matrix<T>::width() const
return 0;
}
-template<class T> QPoint Matrix<T>::size() const
-{
- return QPoint(height(), width());
-}
-
template<class T> T& Matrix<T>::operator()(const int row, const int column)
{
Q_ASSERT(row < height());
@@ -214,7 +277,9 @@ template<class T> T& Matrix<T>::operator()(const int row, const int column)
template<class T> T Matrix<T>::operator()(const int row, const int column) const
{
- return at(row, column);
+ Q_ASSERT(row < height());
+ Q_ASSERT(column < width());
+ return m_matrix.at(row).at(column);
}
template<class T> Matrix<T>& Matrix<T>::operator=(const Matrix<T>& rhs)
diff --git a/sigmod/Object.cpp b/sigmod/Object.cpp
index 803dadc5..74065fd7 100644
--- a/sigmod/Object.cpp
+++ b/sigmod/Object.cpp
@@ -15,19 +15,16 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file sigmod/Object.cpp
+ */
+
// Header include
#include "Object.h"
// Sigmod includes
#include "Macros.h"
-Sigmod::Object::Object(const Object& object) :
- QObject(NULL),
- m_id(object.id()),
- m_parent(object.parent())
-{
-}
-
Sigmod::Object::Object(const Object* parent, const int id) :
QObject(NULL),
m_id(id),
@@ -40,11 +37,11 @@ const Sigmod::Object* Sigmod::Object::parent() const
return m_parent;
}
-const Sigmod::Object* Sigmod::Object::sigmod() const
+const Sigmod::Sigmod* Sigmod::Object::sigmod() const
{
if (m_parent)
return m_parent->sigmod();
- return this;
+ return qobject_cast<const Sigmod*>(this);
}
int Sigmod::Object::id() const
@@ -57,11 +54,6 @@ void Sigmod::Object::setId(const int id)
CHECK(id);
}
-QString Sigmod::Object::className() const
-{
- return QString(metaObject()->className()).section(':', -1);
-}
-
QDomDocument Sigmod::Object::xml(const Object* object)
{
QDomDocument xml(object->className());
@@ -69,6 +61,15 @@ QDomDocument Sigmod::Object::xml(const Object* object)
return xml;
}
+void Sigmod::Object::validateScript(const Script& script)
+{
+}
+
+QString Sigmod::Object::className() const
+{
+ return QString(metaObject()->className()).section(':', -1);
+}
+
QString Sigmod::Object::unused(const QString& variable)
{
return QString("Setting unused variable %1").arg(variable);
diff --git a/sigmod/Object.h b/sigmod/Object.h
index 6b4ca974..23fbbd5c 100644
--- a/sigmod/Object.h
+++ b/sigmod/Object.h
@@ -15,6 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file sigmod/Object.h
+ */
+
#ifndef SIGMOD_OBJECT
#define SIGMOD_OBJECT
@@ -38,34 +42,121 @@
namespace Sigmod
{
+// Forward decarations
+class Sigmod;
+
+/**
+ * \class Sigmod::Object Object.h sigmod/Object.h
+ * \brief Base class for all data structures in a Sigmod.
+ *
+ * The Object class sets up a parenting structure for all Sigmod classes. It also provides an interface for validation,
+ * saving to XML format, as well as loading from XML.
+ */
class SIGMOD_EXPORT Object : public QObject
{
Q_OBJECT
public:
- Object(const Object& object);
+ /**
+ * Constructor.
+ *
+ * \param parent The parent of the object.
+ * \param id The id of the object.
+ */
Object(const Object* parent, const int id);
+ /**
+ * Destructor.
+ */
virtual ~Object();
+ /**
+ * \return The parent of the object.
+ */
const Object* parent() const;
- const Object* sigmod() const;
+ /**
+ * \return The Sigmod that the object belongs to.
+ */
+ const Sigmod* sigmod() const;
+ /**
+ * \return The id of the object.
+ */
int id() const;
+ /**
+ * \return The name of the class of the object without the namespace.
+ */
QString className() const;
+ /**
+ * Convenience function to create a QDomDocument from the QDomElement that is returned from \link Object::save save \endlink .
+ *
+ * \param object The object to create an XML structure from.
+ * \return The XML representation of \p object.
+ */
static QDomDocument xml(const Object* object);
+ /**
+ * Method for validating the object.
+ */
virtual void validate() = 0;
+ /**
+ * Validates a script. It ensures that system modules are not included so that the scripts cannot do anything beyond
+ * interacting with the .
+ *
+ * \param script The script to validate.
+ *
+ * \todo Validate the script.
+ */
+ void validateScript(const Script& script);
+ /**
+ * Loads data from an XML structure.
+ *
+ * \param xml The XML data structure to load data from.
+ */
virtual void load(const QDomElement& xml) = 0;
+ /**
+ * Saves the data of the object to XML.
+ *
+ * \return An XML representation of the class.
+ */
virtual QDomElement save() const = 0;
signals:
+ /**
+ * Signal for when the object encounters something unexpected, but it does not invalid when validating.
+ *
+ * \param message The message.
+ */
void valMessage(const QString& message) const;
+ /**
+ * Signal for when the object encounters a value that is either confusing or not advised, but does not
+ * render the Sigmod as inconsistent.
+ *
+ * \param message The warning.
+ */
void valWarning(const QString& message) const;
+ /**
+ * Signal for when the object encounters an unexpected value that introduces an inconsistency in the Sigmod.
+ *
+ * \param message The error.
+ */
void valError(const QString& message) const;
+ /**
+ * Signal for when a value was set, but it may not be optimal.
+ *
+ * \param message The warning.
+ */
void warning(const QString& message) const;
+ /**
+ * Signal for when a value assignment was attempted, but the value was invalid.
+ *
+ * \param message The error.
+ */
void error(const QString& message) const;
+ /**
+ * Signal for when the object has changed.
+ */
void changed() const;
protected:
void setId(const int id);
@@ -229,7 +320,7 @@ template<> inline QDomElement Object::saveValue<QImage>(const QString& name, con
QByteArray bytes;
QBuffer* buffer = new QBuffer(&bytes);
buffer->open(QIODevice::WriteOnly);
- value.save(buffer, "PNG");
+ value.save(buffer, "PNG", 0);
element.appendChild(QDomDocument().createTextNode(bytes.toBase64()));
delete buffer;
return element;
@@ -290,4 +381,7 @@ template<typename T> inline QDomElement Object::saveMatrix(const QString& name,
}
+// This makes the moc file happy.
+#include "Sigmod.h"
+
#endif
diff --git a/sigmod/Script.h b/sigmod/Script.h
index 5fe87ad9..c884aaf5 100644
--- a/sigmod/Script.h
+++ b/sigmod/Script.h
@@ -15,6 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file sigmod/Script.h
+ */
+
#ifndef SIGMOD_SCRIPT
#define SIGMOD_SCRIPT
@@ -26,16 +30,55 @@
namespace Sigmod
{
+/**
+ * \class Sigmod::Script Script.h sigmod/Script.h
+ * \brief Class that describes a script for the game engine.
+ */
class SIGMOD_EXPORT Script
{
public:
- Script();
- Script(const QString& interpreter, const QString& script);
+ /**
+ * Constructor.
+ *
+ * \param interpreter The language of the script.
+ * \param script The code for the script.
+ */
+ explicit Script(const QString& interpreter = "", const QString& script = "");
+ /**
+ * Set the language of the script. The default game engine uses Kross <http://kross.dipe.org/> to
+ * run the scripts. The following values are valid for Kross:
+ *
+ * - \b mono -- C# <http://www.mono-project.com/Main_Page>
+ * - \b falcon -- Falcon <http://www.falconpl.org/>
+ * - \b java -- Java <http://www.java.com/en/>
+ * - \b lua -- Lua <http://www.lua.org/>
+ * - \b php -- PHP <http://www.php.net/>
+ * - \b python -- Python <http://www.python.org/>
+ * - \b ruby -- Ruby <http://www.ruby-lang.org/en/>
+ *
+ * Other languages may be added in the future.
+ *
+ * \param interpreter The language of the script.
+ */
void setInterpreter(const QString& interpreter);
+ /**
+ *
+ * \param script The code for the script.
+ */
void setScript(const QString& script);
+ /**
+ * \sa setInterpreter
+ *
+ * \return The language of the script.
+ */
QString interpreter() const;
+ /**
+ * \sa setScript
+ *
+ * \return The code for the script.
+ */
QString script() const;
Script& operator=(const Script& rhs);
@@ -46,12 +89,6 @@ class SIGMOD_EXPORT Script
QString m_script;
};
-inline Script::Script() :
- m_interpreter(""),
- m_script("")
-{
-}
-
inline Script::Script(const QString& interpreter, const QString& script) :
m_interpreter(interpreter),
m_script(script)
diff --git a/sigmod/Sigmod.h b/sigmod/Sigmod.h
index e902aaac..544d1957 100644
--- a/sigmod/Sigmod.h
+++ b/sigmod/Sigmod.h
@@ -15,6 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file simod/Sigmod.h
+ */
+
#ifndef SIGMOD_SIGMOD
#define SIGMOD_SIGMOD
@@ -53,17 +57,57 @@ class Trainer;
class Type;
class Weather;
+/**
+ * \class Sigmod::Sigmod Sigmod.h sigmod/Sigmod.h
+ * \brief Main class used to create and manage Sigmods.
+ *
+ * The Sigmod class describes an entire set of objects for use with the game engine.
+ * Games will refuse to run if the \link Sigmod::validate validate \endlink returns
+ * any errors. Warnings will not stop the engine from running the Sigmod, but they
+ * should be minimized.
+ */
class SIGMOD_EXPORT Sigmod : public Object
{
Q_OBJECT
public:
+ /**
+ * Default constructor.
+ */
Sigmod();
+ /**
+ * Copy constructor.
+ *
+ * \param sigmod The Sigmod to copy.
+ */
Sigmod(const Sigmod& sigmod);
+ /**
+ * XML data constructor.
+ *
+ * \param xml The XML structure to extract the data from.
+ */
Sigmod(const QDomElement& xml);
+ /**
+ * Destructor.
+ */
~Sigmod();
+ /**
+ * Check to make sure the Sigmod is valid.
+ */
+ void validate();
+
+ /**
+ * Load data from XML.
+ *
+ * \param xml The XML structure to extract data from.
+ */
void load(const QDomElement& xml);
+ /**
+ * Get the data for the badge in XML format.
+ *
+ * \return The XML structure representing the badge.
+ */
QDomElement save() const;
void setTitle(const QString& title);
@@ -354,8 +398,6 @@ class SIGMOD_EXPORT Sigmod : public Object
Sigmod& operator=(const Sigmod& rhs);
private:
- void validate();
-
int newAbilityId() const;
Ability* newAbility(Ability* ability);