diff options
Diffstat (limited to 'sigmod/Item.cpp')
| -rw-r--r-- | sigmod/Item.cpp | 133 |
1 files changed, 36 insertions, 97 deletions
diff --git a/sigmod/Item.cpp b/sigmod/Item.cpp index e6f521dd..98a2e274 100644 --- a/sigmod/Item.cpp +++ b/sigmod/Item.cpp @@ -68,11 +68,11 @@ void Sigmod::Item::validate() TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); - TEST(setType, type); - TEST(setPrice, price); + TEST(type); + TEST(price); if (m_sellable) - TEST(setSellPrice, sellPrice); - TEST(setWeight, weight); + TEST(sellPrice); + TEST(weight); TEST_END(); } @@ -103,101 +103,40 @@ QDomElement Sigmod::Item::save() const return xml; } -void Sigmod::Item::setName(const QString& name) -{ - CHECK(name); -} - -void Sigmod::Item::setSellable(const bool sellable) -{ - CHECK(sellable); -} - -void Sigmod::Item::setType(const int type) -{ - if (!sigmod()->itemTypeById(type)) - emit(error(bounds("type", type))); - else - CHECK(type); -} - -void Sigmod::Item::setPrice(const int price) -{ - if ((price <= 0) || (sigmod()->rules()->maxMoney() < price)) - emit(error(bounds("price", 1, sigmod()->rules()->maxMoney(), price))); - else - CHECK(price); -} - -void Sigmod::Item::setSellPrice(const int sellPrice) -{ - if ((sellPrice < 0) || (m_price < sellPrice)) - emit(error(bounds("sellPrice", 0, m_price, sellPrice))); - else - CHECK(sellPrice); -} - -void Sigmod::Item::setWeight(const int weight) -{ +SETTER(Item, QString&, Name, name) +SETTER(Item, bool, Sellable, sellable) +SETTER(Item, int, Type, type) +SETTER(Item, int, Price, price) +SETTER(Item, int, SellPrice, sellPrice) +SETTER(Item, int, Weight, weight) +SETTER(Item, QString&, Description, description) +SETTER(Item, Sigcore::Script&, Script, script) + +GETTER(Item, QString, name) +GETTER(Item, bool, sellable) +GETTER(Item, int, type) +GETTER(Item, int, price) +GETTER(Item, int, sellPrice) +GETTER(Item, int, weight) +GETTER(Item, QString, description) +GETTER(Item, Sigcore::Script, script) + +CHECK_DEFAULT(Item, QString&, name) +CHECK_DEFAULT(Item, bool, sellable) +CHECK_INDEX(Item, int, type, sigmod(), type) +CHECK_BEGIN(Item, int, price) + TBOUNDS(price, 1, sigmod()->rules()->maxMoney()) +CHECK_END() +CHECK_BEGIN(Item, int, sellPrice) + TBOUNDS(sellPrice, 0, m_price) +CHECK_END() +CHECK_BEGIN(Item, int, weight) const ItemType* type = sigmod()->itemTypeById(m_type); if (type) - { - if ((weight < 0) || (type->maxWeight() < weight)) - emit(error(bounds("weight", 0, type->maxWeight(), weight))); - else - CHECK(weight); - } -} - -void Sigmod::Item::setDescription(const QString& description) -{ - CHECK(description); -} - -void Sigmod::Item::setScript(const Sigcore::Script& script) -{ - CHECK(script); -} - -QString Sigmod::Item::name() const -{ - return m_name; -} - -bool Sigmod::Item::sellable() const -{ - return m_sellable; -} - -int Sigmod::Item::type() const -{ - return m_type; -} - -int Sigmod::Item::price() const -{ - return m_price; -} - -int Sigmod::Item::sellPrice() const -{ - return m_sellPrice; -} - -int Sigmod::Item::weight() const -{ - return m_weight; -} - -QString Sigmod::Item::description() const -{ - return m_description; -} - -Sigcore::Script Sigmod::Item::script() const -{ - return m_script; -} + TBOUNDS(weight, 0, type->maxWeight()) +CHECK_END() +CHECK_DEFAULT(Item, QString&, description) +CHECK_DEFAULT(Item, Sigcore::Script&, script) Sigmod::Item& Sigmod::Item::operator=(const Item& rhs) { |
