/* * Copyright 2007-2008 Ben Boeckel * * 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 . */ #include "Pokemod.h" #include "CoinListObject.h" const QStringList CoinListObject::TypeStr = QStringList() << "Item" << "Pokémon"; CoinListObject::CoinListObject(const CoinListObject& object) : Object("CoinListObject", object.parent(), object.id()) { *this = object; } CoinListObject::CoinListObject(const Object* parent, const int id) : Object("CoinListObject", parent, id), m_type(Item), m_object(INT_MAX), m_amount(1), m_cost(0) { } CoinListObject::CoinListObject(const CoinListObject& object, const Object* parent, const int id) : Object("CoinListObject", parent, id) { *this = object; } CoinListObject::CoinListObject(const QDomElement& xml, const Object* parent, const int id) : Object("CoinListObject", parent, id) { load(xml, id); } bool CoinListObject::validate() const { // TODO: validate // bool valid = true; // static_cast(pokemod())->validationMsg(QString("------Object with id %1---").arg(id()), Pokemod::V_Msg); // if (Item == m_type) // { // if (static_cast(pokemod())->itemIndex(m_object) == INT_MAX) // { // static_cast(pokemod())->validationMsg("Invalid item"); // valid = false; // } // } // else if (Species == m_type) // { // if (static_cast(pokemod())->speciesIndex(m_object) == INT_MAX) // { // static_cast(pokemod())->validationMsg("Invalid Species"); // valid = false; // } // } // else // { // static_cast(pokemod())->validationMsg("Invalid type"); // valid = false; // } // if (!m_amount || ((1 < m_amount) && (Species == m_type))) // { // static_cast(pokemod())->validationMsg("Invalid amount"); // valid = false; // } // return valid; } void CoinListObject::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(int, type); LOAD(int, object); LOAD(int, amount); LOAD(int, cost); } QDomElement CoinListObject::save() const { SAVE_CREATE(); SAVE(int, type); SAVE(int, object); SAVE(int, amount); SAVE(int, cost); return xml; } void CoinListObject::setType(const int type) throw(BoundsException) { if (End <= type) error("type"); m_type = type; m_object = INT_MAX; } void CoinListObject::setObject(const int object) throw(BoundsException) { if (((Item == m_type) && (static_cast(pokemod())->itemIndex(object) == INT_MAX)) || ((Species == m_type) && (static_cast(pokemod())->speciesIndex(object) == INT_MAX))) error("object"); m_object = object; } void CoinListObject::setAmount(const int amount) throw(BoundsException) { if (!amount || ((Species == m_type) && (1 < amount))) error("amount"); m_amount = amount; } void CoinListObject::setCost(const int cost) { m_cost = cost; } int CoinListObject::type() const { return m_type; } int CoinListObject::object() const { return m_object; } int CoinListObject::amount() const { return m_amount; } int CoinListObject::cost() const { return m_cost; } CoinListObject& CoinListObject::operator=(const CoinListObject& rhs) { if (this == &rhs) return *this; COPY(type); COPY(object); COPY(amount); COPY(cost); return *this; }