diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-10-13 21:05:50 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-10-13 21:05:50 +0000 |
| commit | 460e7bdf3f6c1de69f41b02a16deb85522ae3c49 (patch) | |
| tree | 3b80ad00d5f021f63d3f890af2e017af314d2106 /sigmod | |
| parent | b427a8cdf13aabe59af60acf0a4264d84ae3ff7a (diff) | |
[FIX] Sprite no longer stores a QImage, but a QByteArray
[FIX] Preparing for move to a collaged map instead of a tiled map
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@278 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'sigmod')
| -rw-r--r-- | sigmod/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | sigmod/Matrix.h | 63 | ||||
| -rw-r--r-- | sigmod/Object.h | 18 | ||||
| -rw-r--r-- | sigmod/Script.cpp | 68 | ||||
| -rw-r--r-- | sigmod/Script.h | 46 | ||||
| -rw-r--r-- | sigmod/Sprite.cpp | 7 | ||||
| -rw-r--r-- | sigmod/Sprite.h | 8 | ||||
| -rw-r--r-- | sigmod/Tile.cpp | 3 | ||||
| -rw-r--r-- | sigmod/sigmod.pro | 1 |
9 files changed, 140 insertions, 76 deletions
diff --git a/sigmod/CMakeLists.txt b/sigmod/CMakeLists.txt index cf1d12fa..7663c0c9 100644 --- a/sigmod/CMakeLists.txt +++ b/sigmod/CMakeLists.txt @@ -69,6 +69,7 @@ SET(sigmod_SRCS Nature.cpp Object.cpp Rules.cpp + Script.cpp Sigmod.cpp Skin.cpp Sound.cpp @@ -98,7 +99,6 @@ SET_TARGET_PROPERTIES(sigmod ) TARGET_LINK_LIBRARIES(sigmod ${QT_QTCORE_LIBRARY} - ${QT_QTGUI_LIBRARY} ${QT_QTXML_LIBRARY} ) diff --git a/sigmod/Matrix.h b/sigmod/Matrix.h index 16d3a5d0..1726804c 100644 --- a/sigmod/Matrix.h +++ b/sigmod/Matrix.h @@ -127,6 +127,27 @@ template<class T> class SIGMOD_EXPORT Matrix QVector<T> column(const int column) const; /** + * Get a matrix from within the matrix. + * + * \param top The top-most part of the matrix. + * \param left The left-most part of the matrix. + * \param height The height of the new matrix. + * \param width The width of the new matrix. + * \return The matrix. + */ + Matrix<T> mid(const int top, const int left, const int height, const int width) const; + /** + * Set a matrix from within the matrix. + * + * \param top The top-most part of the matrix. + * \param left The left-most part of the matrix. + * \param height The height of the new matrix. + * \param width The width of the new matrix. + * \param value The value to set the mid to. + */ + void setMid(const int top, const int left, const int height, const int width, const T& value); + + /** * \return The height of the matrix. */ int height() const; @@ -184,6 +205,7 @@ template<class T> void Matrix<T>::addColumn(const T& value) template<class T> void Matrix<T>::insertRow(const int row, const T& value) { + Q_ASSERT(0 <= row); Q_ASSERT(row <= height()); if (!height() || !width()) m_matrix.append(QVector<T>(1, value)); @@ -193,6 +215,7 @@ template<class T> void Matrix<T>::insertRow(const int row, const T& value) template<class T> void Matrix<T>::insertColumn(const int column, const T& value) { + Q_ASSERT(0 <= column); Q_ASSERT(column <= width()); if (!height() || !width()) m_matrix.append(QVector<T>(1, value)); @@ -205,6 +228,7 @@ 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(0 <= row); Q_ASSERT(row < height()); if (height() == 1) m_matrix.clear(); @@ -214,6 +238,7 @@ template<class T> void Matrix<T>::deleteRow(const int row) template<class T> void Matrix<T>::deleteColumn(const int column) { + Q_ASSERT(0 <= column); Q_ASSERT(column < width()); if (width() == 1) m_matrix.clear(); @@ -243,12 +268,14 @@ template<class T> void Matrix<T>::resize(const int newHeight, const int newWidth template<class T> QVector<T> Matrix<T>::row(const int row) const { + Q_ASSERT(0 <= row); Q_ASSERT(row < height()); return m_matrix.at(row); } template<class T> QVector<T> Matrix<T>::column(const int column) const { + Q_ASSERT(0 <= column); Q_ASSERT(column < width()); QVector<T> col; foreach (QVector<T> row, m_matrix) @@ -256,6 +283,42 @@ template<class T> QVector<T> Matrix<T>::column(const int column) const return col; } +template<class T> Matrix<T> Matrix<T>::mid(const int top, const int left, const int height, const int width) const +{ + Q_ASSERT(0 <= top); + Q_ASSERT(top < height()); + Q_ASSERT(0 <= left); + Q_ASSERT(left < width()); + Q_ASSERT(0 <= height); + Q_ASSERT(top + height <= height()); + Q_ASSERT(0 <= width); + Q_ASSERT(left + width <= width()); + Matrix<T> matrix(height, width); + for (int i = 0; i < height; ++i) + { + for (int j = 0; j < width; ++j) + matrix(i, j) = operator()(top + i, left + j); + } + return matrix; +} + +template<class T> void Matrix<T>::setMid(const int top, const int left, const int height, const int width, const T& value) +{ + Q_ASSERT(0 <= top); + Q_ASSERT(top < height()); + Q_ASSERT(0 <= left); + Q_ASSERT(left < width()); + Q_ASSERT(0 <= height); + Q_ASSERT(top + height <= height()); + Q_ASSERT(0 <= width); + Q_ASSERT(left + width <= width()); + for (int i = 0; i < height; ++i) + { + for (int j = 0; j < width; ++j) + operator()(top + i, left + j) = value; + } +} + template<class T> int Matrix<T>::height() const { return m_matrix.size(); diff --git a/sigmod/Object.h b/sigmod/Object.h index efb20abb..6e0390a7 100644 --- a/sigmod/Object.h +++ b/sigmod/Object.h @@ -34,7 +34,6 @@ #include <QtCore/QPoint> #include <QtCore/QVariant> #include <QtCore/QVarLengthArray> -#include <QtGui/QImage> #include <QtXml/QDomElement> // C includes @@ -204,11 +203,6 @@ template<> inline void Object::loadValue<QPoint>(const QDomElement& xml, QPoint* value->setY(xml.attribute("y", "0").toInt()); } -template<> inline void Object::loadValue<QImage>(const QDomElement& xml, QImage* value) -{ - *value = QImage::fromData(QByteArray::fromBase64(xml.firstChild().toText().data().toUtf8())); -} - template<> inline void Object::loadValue<QByteArray>(const QDomElement& xml, QByteArray* value) { *value = QByteArray::fromBase64(xml.firstChild().toText().data().toUtf8()); @@ -305,18 +299,6 @@ template<> inline QDomElement Object::saveValue<QPoint>(const QString& name, con return element; } -template<> inline QDomElement Object::saveValue<QImage>(const QString& name, const QImage& value) -{ - QDomElement element = QDomDocument().createElement(name); - QByteArray bytes; - QBuffer* buffer = new QBuffer(&bytes); - buffer->open(QIODevice::WriteOnly); - value.save(buffer, "PNG", 0); - element.appendChild(QDomDocument().createTextNode(bytes.toBase64())); - delete buffer; - return element; -} - template<> inline QDomElement Object::saveValue<QByteArray>(const QString& name, const QByteArray& value) { QDomElement element = QDomDocument().createElement(name); diff --git a/sigmod/Script.cpp b/sigmod/Script.cpp new file mode 100644 index 00000000..55dc02b0 --- /dev/null +++ b/sigmod/Script.cpp @@ -0,0 +1,68 @@ +/* + * 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/>. + */ + +/** + * \file sigmod/Script.cpp + */ + +// Header include +#include "Script.h" + +Sigmod::Script::Script(const QString& interpreter, const QString& script) : + m_interpreter(interpreter), + m_script(script) +{ +} + +void Sigmod::Script::setInterpreter(const QString& interpreter) +{ + m_interpreter = interpreter; +} + +void Sigmod::Script::setScript(const QString& script) +{ + m_script = script; +} + +QString Sigmod::Script::interpreter() const +{ + return m_interpreter; +} + +QString Sigmod::Script::script() const +{ + return m_script; +} + +Sigmod::Script& Sigmod::Script::operator=(const Script& rhs) +{ + if (this == &rhs) + return *this; + m_interpreter = rhs.m_interpreter; + m_script = rhs.m_script; + return *this; +} + +bool Sigmod::Script::operator==(const Script& rhs) const +{ + return ((m_interpreter == rhs.m_interpreter) && (m_script == rhs.m_script)); +} + +bool Sigmod::Script::operator!=(const Script& rhs) const +{ + return !(*this == rhs); +} diff --git a/sigmod/Script.h b/sigmod/Script.h index c884aaf5..13c09aac 100644 --- a/sigmod/Script.h +++ b/sigmod/Script.h @@ -88,52 +88,6 @@ class SIGMOD_EXPORT Script QString m_interpreter; QString m_script; }; - -inline Script::Script(const QString& interpreter, const QString& script) : - m_interpreter(interpreter), - m_script(script) -{ -} - -inline void Script::setInterpreter(const QString& interpreter) -{ - m_interpreter = interpreter; -} - -inline void Script::setScript(const QString& script) -{ - m_script = script; -} - -inline QString Script::interpreter() const -{ - return m_interpreter; -} - -inline QString Script::script() const -{ - return m_script; -} - -inline Script& Script::operator=(const Script& rhs) -{ - if (this == &rhs) - return *this; - m_interpreter = rhs.m_interpreter; - m_script = rhs.m_script; - return *this; -} - -inline bool Script::operator==(const Script& rhs) const -{ - return ((m_interpreter == rhs.m_interpreter) && (m_script == rhs.m_script)); -} - -inline bool Script::operator!=(const Script& rhs) const -{ - return !(*this == rhs); -} - } Q_DECLARE_METATYPE(Sigmod::Script) diff --git a/sigmod/Sprite.cpp b/sigmod/Sprite.cpp index 0261385a..562a9a30 100644 --- a/sigmod/Sprite.cpp +++ b/sigmod/Sprite.cpp @@ -80,10 +80,9 @@ void Sigmod::Sprite::setName(const QString& name) CHECK(name); } -void Sigmod::Sprite::setSprite(const QImage& sprite) +void Sigmod::Sprite::setSprite(const QByteArray& sprite) { - m_sprite = sprite; - emit(changed()); + CHECK(sprite); } QString Sigmod::Sprite::name() const @@ -91,7 +90,7 @@ QString Sigmod::Sprite::name() const return m_name; } -QImage Sigmod::Sprite::sprite() const +QByteArray Sigmod::Sprite::sprite() const { return m_sprite; } diff --git a/sigmod/Sprite.h b/sigmod/Sprite.h index b11f33fd..13b2fc19 100644 --- a/sigmod/Sprite.h +++ b/sigmod/Sprite.h @@ -22,7 +22,7 @@ #include "Object.h" // Qt includes -#include <QtGui/QImage> +#include <QtCore/QByteArray> namespace Sigmod { @@ -46,15 +46,15 @@ class SIGMOD_EXPORT Sprite : public Object QDomElement save() const; void setName(const QString& name); - void setSprite(const QImage& sprite); + void setSprite(const QByteArray& sprite); QString name() const; - QImage sprite() const; + QByteArray sprite() const; Sprite& operator=(const Sprite& rhs); private: QString m_name; - QImage m_sprite; + QByteArray m_sprite; }; } diff --git a/sigmod/Tile.cpp b/sigmod/Tile.cpp index 31f51c6b..b5c9d6e0 100644 --- a/sigmod/Tile.cpp +++ b/sigmod/Tile.cpp @@ -92,9 +92,6 @@ void Sigmod::Tile::setSprite(const int sprite) { if (qobject_cast<const Sigmod*>(sigmod())->spriteIndex(sprite) == INT_MAX) emit(error(bounds("sprite"))); - // FIXME: remove if doing collaging - else if (qobject_cast<const Sigmod*>(sigmod())->spriteById(sprite)->sprite().size() != QSize(64, 64)) - emit(error("Sprite is the wrong dimensions")); else CHECK(sprite); } diff --git a/sigmod/sigmod.pro b/sigmod/sigmod.pro index 5d482a4c..4823b875 100644 --- a/sigmod/sigmod.pro +++ b/sigmod/sigmod.pro @@ -40,6 +40,7 @@ SOURCES += Ability.cpp \ Nature.cpp \ Object.cpp \ Rules.cpp \ + Script.cpp \ Sigmod.cpp \ Skin.cpp \ Sound.cpp \ |
