From c1793a87ebea8c8e1bb2d5d1a409d105bfae3871 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 18 Aug 2008 18:51:31 +0000 Subject: [FIX] Script to make a tarball now defaults to HEAD for the revision [FIX] Enumeration types used to help remove some checks [FIX] Macro code moved to static members of Object (not all though) [FIX] Scripting wrappers now share information by keeping track of already-created instances of the wrapper [FIX] Scripting methods are now Q_SCRIPTABLE and not slots git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@239 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/Object.cpp | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) (limited to 'pokemod/Object.cpp') diff --git a/pokemod/Object.cpp b/pokemod/Object.cpp index 2ad06fef..b0fb3b64 100644 --- a/pokemod/Object.cpp +++ b/pokemod/Object.cpp @@ -19,7 +19,15 @@ #include "Object.h" // Pokemod includes +#include "Fraction.h" #include "Macros.h" +#include "Script.h" + +// Qt includes +#include +#include +#include +#include Pokemod::Object::Object(const Object& object) : QObject(NULL), @@ -62,6 +70,13 @@ QString Pokemod::Object::className() const return QString(metaObject()->className()).section(':', -1); } +QDomDocument Pokemod::Object::xml(const Object* object) +{ + QDomDocument xml(object->className()); + xml.appendChild(object->save()); + return xml; +} + QString Pokemod::Object::unused(const QString& variable) { return QString("Setting unused variable %1").arg(variable); @@ -85,3 +100,109 @@ QString Pokemod::Object::subclass(const QString& subclass, const QString& name) void Pokemod::Object::clear() { } + +namespace Pokemod +{ +template<> void Object::loadValue(const QDomElement& xml, bool* value) +{ + *value = (xml.firstChild().toText().data() == "true"); +} + +template<> void Object::loadValue(const QDomElement& xml, int* value) +{ + *value = xml.firstChild().toText().data().toInt(); +} + +template<> void Object::loadValue(const QDomElement& xml, Fraction* value) +{ + value->set(xml.attribute("numerator", "1").toInt(), xml.attribute("denominator", "1").toInt()); +} + +template<> void Object::loadValue(const QDomElement& xml, QPoint* value) +{ + value->setX(xml.attribute("x", "0").toInt()); + value->setY(xml.attribute("y", "0").toInt()); +} + +template<> void Object::loadValue(const QDomElement& xml, QPixmap* value) +{ + // FIXME: QPixmap::fromData static member would be nice + *value = QPixmap::fromImage(QImage::fromData(QByteArray::fromBase64(xml.firstChild().toText().data().toUtf8()))); +} + +template<> void Object::loadValue(const QDomElement& xml, QByteArray* value) +{ + *value = QByteArray::fromBase64(xml.firstChild().toText().data().toUtf8()); +} + +template<> void Object::loadValue