summaryrefslogtreecommitdiffstats
path: root/pokemod/Tile.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-04-15 18:57:00 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-04-15 18:57:00 +0000
commite1b5d7bc705810ac15ed36924617af52abdc8e81 (patch)
tree0dae5af4e2737372ec479bb9ccdd2201edf684a8 /pokemod/Tile.cpp
parent12d5161318a4d8d781f896812f5a95fa7b46d8a8 (diff)
[FIX] Object::mid -> m_id
[FIX] XML is now used [FIX] Images are stored in the XML file and classes rather than relying on external images [FIX] Frac no longer keeps track of its type; the class should do it [ADD] pokemod/Object.cpp git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@97 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Tile.cpp')
-rw-r--r--pokemod/Tile.cpp99
1 files changed, 40 insertions, 59 deletions
diff --git a/pokemod/Tile.cpp b/pokemod/Tile.cpp
index 0c7a8195..2eb80173 100644
--- a/pokemod/Tile.cpp
+++ b/pokemod/Tile.cpp
@@ -15,6 +15,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+// Qt includes
+#include <QBuffer>
+
// Pokemod includes
#include "Pokemod.h"
@@ -42,10 +45,10 @@ Tile::Tile(const Pokemod* pokemod, const Tile& tile, const int id) :
*this = tile;
}
-Tile::Tile(const Pokemod* pokemod, const QString& fileName, const int id) :
+Tile::Tile(const Pokemod* pokemod, const QDomElement& xml, const int id) :
Object("Tile", pokemod, id)
{
- load(fileName, id);
+ load(xml, id);
}
bool Tile::validate() const
@@ -57,11 +60,6 @@ bool Tile::validate() const
pokemod()->validationMsg("Name is not defined");
valid = false;
}
- if (!QFile::exists(pic()))
- {
- pokemod()->validationMsg("Cannot find tile image");
- valid = false;
- }
if ((m_hmType == Pokemod::HM_Waterfall) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down]))
{
pokemod()->validationMsg("A waterfall tile must be accessible from above and below");
@@ -98,44 +96,31 @@ bool Tile::validate() const
return valid;
}
-void Tile::load(const QString& fileName, int id) throw(Exception)
+void Tile::load(const QDomElement& xml, int id)
{
- Ini ini(fileName);
- if (id == INT_MAX)
- ini.getValue("id", id);
- setId(id);
- int i;
- int j;
- ini.getValue("name", m_name);
- ini.getValue("from-up", m_from[Pokemod::D_Up], false);
- ini.getValue("from-down", m_from[Pokemod::D_Down], false);
- ini.getValue("from-left", m_from[Pokemod::D_Left], false);
- ini.getValue("from-right", m_from[Pokemod::D_Right], false);
- ini.getValue("wildChance-n", i, 1);
- ini.getValue("wildChance-d", j, 1);
- m_wildChance.set(i, j);
- ini.getValue("hmType", m_hmType);
- ini.getValue("under", m_under);
- ini.getValue("forceType", m_forceType);
- ini.getValue("forceDirection", m_forceDirection);
+ LOAD_ID();
+ LOAD(QString, name);
+ LOAD(QPixmap, sprite);
+ LOAD_ARRAY(bool, from, Pokemod::D_End);
+ LOAD(Frac, wildChance);
+ LOAD(int, hmType);
+ LOAD(int, under);
+ LOAD(int, forceType);
+ LOAD(int, forceDirection);
}
-void Tile::save() const throw(Exception)
+QDomElement Tile::save() const
{
- Ini ini;
- ini.addField("id", id());
- ini.addField("name", m_name);
- ini.addField("from-up", m_from[Pokemod::D_Up]);
- ini.addField("from-down", m_from[Pokemod::D_Down]);
- ini.addField("from-left", m_from[Pokemod::D_Left]);
- ini.addField("from-right", m_from[Pokemod::D_Right]);
- ini.addField("wildChance-n", m_wildChance.numerator());
- ini.addField("wildChance-d", m_wildChance.denominator());
- ini.addField("hmType", m_hmType);
- ini.addField("under", m_under);
- ini.addField("forceType", m_forceType);
- ini.addField("forceDirection", m_forceDirection);
- ini.save(QString("%1/tile/%2.pini").arg(pokemod()->path()).arg(m_name));
+ SAVE_CREATE();
+ SAVE(QString, name);
+ SAVE(QPixmap, sprite);
+ SAVE_ARRAY(bool, from, Pokemod::D_End);
+ SAVE(Frac, wildChance);
+ SAVE(int, hmType);
+ SAVE(int, under);
+ SAVE(int, forceType);
+ SAVE(int, forceDirection);
+ return xml;
}
void Tile::setName(const QString& name)
@@ -143,13 +128,10 @@ void Tile::setName(const QString& name)
m_name = name;
}
-void Tile::setPic(const QString& fileName) throw(Exception)
+void Tile::setSprite(const QPixmap& sprite) throw(Exception)
{
- QFile file(pic());
- if (file.exists() && !file.remove())
- throw(RemoveException(className(), file.fileName()));
- if (!QFile::copy(fileName, pic()))
- throw(SaveException(className(), file.fileName()));
+ // TODO: check dimension
+ m_sprite = sprite;
}
void Tile::setFrom(const int direction, const bool state) throw(BoundsException)
@@ -159,9 +141,9 @@ void Tile::setFrom(const int direction, const bool state) throw(BoundsException)
m_from[direction] = state;
}
-void Tile::setWildChance(const int numerator, const int denominator) throw(Exception)
+void Tile::setWildChance(const Frac& wildChance) throw(Exception)
{
- m_wildChance.set(numerator, denominator);
+ m_wildChance = wildChance;
}
void Tile::setHMType(const int hmType) throw(BoundsException)
@@ -208,9 +190,9 @@ QString Tile::name() const
return m_name;
}
-QString Tile::pic() const
+QPixmap Tile::sprite() const
{
- return QString("%1/tile/%2.png").arg(pokemod()->path()).arg(m_name);
+ return m_sprite;
}
bool Tile::from(const int direction) const throw(BoundsException)
@@ -249,13 +231,12 @@ Tile& Tile::operator=(const Tile& rhs)
{
if (this == &rhs)
return *this;
- m_name = rhs.m_name;
- for (int i = 0; i < Pokemod::D_End; ++i)
- m_from[i] = rhs.m_from[i];
- m_wildChance = rhs.m_wildChance;
- m_hmType = rhs.m_hmType;
- m_under = rhs.m_under;
- m_forceType = rhs.m_forceType;
- m_forceDirection = rhs.m_forceDirection;
+ COPY(name);
+ COPY_ARRAY(from, Pokemod::D_End);
+ COPY(wildChance);
+ COPY(hmType);
+ COPY(under);
+ COPY(forceType);
+ COPY(forceDirection);
return *this;
}