diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-02 08:42:08 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-02 08:42:08 +0000 |
| commit | 822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd (patch) | |
| tree | 40dc605213eff20f62b16e5f54e5e5e03d744d63 /pokemod/Item.cpp | |
| parent | 696414f1dc8bc419427efb6c1abe1bbae0a68a56 (diff) | |
[FIX] Exceptions no longer used in pokemod
[DEL] Exception and BugCatcher are no longer needed
[ADD] Object.cpp added
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@119 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Item.cpp')
| -rw-r--r-- | pokemod/Item.cpp | 91 |
1 files changed, 40 insertions, 51 deletions
diff --git a/pokemod/Item.cpp b/pokemod/Item.cpp index 21d3c118..80dd77f0 100644 --- a/pokemod/Item.cpp +++ b/pokemod/Item.cpp @@ -22,6 +22,9 @@ #include "ItemEffect.h" #include "Pokemod.h" +// Qt includes +#include <QSet> + Item::Item(const Item& item) : Object("Item", item.parent(), item.id()) { @@ -55,44 +58,24 @@ Item::~Item() clear(); } -bool Item::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Item \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->itemTypeIndex(m_type) == INT_MAX) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid item type"); -// valid = false; -// } -// if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < m_price) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid price"); -// valid = false; -// } -// if (effectCount()) -// { -// QMap<int, bool> idChecker; -// foreach (ItemEffect* effect, m_effects) -// { -// if (!effect->isValid()) -// valid = false; -// if (idChecker[effect->id()]) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); -// idChecker[effect->id()] = true; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("There are no effects"); -// valid = false; -// } -// return valid; +void Item::validate(QTextStream& stream) +{ + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setType, type); + TEST(setPrice, price); + if (!effectCount()) + error(stream, "There are no effects"); + QSet<int> idChecker; + foreach (ItemEffect* effect, m_effects) + { + if (!effect->isValid(stream)) + setValid(false); + if (idChecker.contains(effect->id())) + subclassError(stream, "effect", effect->id()); + idChecker.insert(effect->id()); + } } void Item::load(const QDomElement& xml, int id) @@ -128,17 +111,23 @@ void Item::setSellable(const bool sellable) m_sellable = sellable; } -void Item::setType(const int type) throw(BoundsException) +void Item::setType(const int type) { if (static_cast<const Pokemod*>(pokemod())->itemTypeIndex(type) == INT_MAX) - error<BoundsException>("type"); + { + boundsError("type"); + return; + } m_type = type; } -void Item::setPrice(const int price) throw(BoundsException) +void Item::setPrice(const int price) { if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < price) - error<BoundsException>("price"); + { + boundsError("price"); + return; + } m_price = price; } @@ -172,26 +161,26 @@ QString Item::description() const return m_description; } -const ItemEffect* Item::effect(const int index) const throw(IndexException) +const ItemEffect* Item::effect(const int index) const { if (effectCount() <= index) - warning<IndexException>("effect"); + return NULL; return m_effects.at(index); } -ItemEffect* Item::effect(const int index) throw(IndexException) +ItemEffect* Item::effect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return NULL; return m_effects[index]; } -const ItemEffect* Item::effectById(const int id) const throw(IndexException) +const ItemEffect* Item::effectById(const int id) const { return effect(effectIndex(id)); } -ItemEffect* Item::effectById(const int id) throw(IndexException) +ItemEffect* Item::effectById(const int id) { return effect(effectIndex(id)); } @@ -232,15 +221,15 @@ ItemEffect* Item::newEffect(ItemEffect* effect) return effect; } -void Item::deleteEffect(const int index) throw(IndexException) +void Item::deleteEffect(const int index) { if (effectCount() <= index) - error<IndexException>("effect"); + return; delete m_effects[index]; m_effects.removeAt(index); } -void Item::deleteEffectById(const int id) throw(IndexException) +void Item::deleteEffectById(const int id) { deleteEffect(effectIndex(id)); } |
