/* * 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 . */ // Header include #include "CoinListObject.h" // Pokemod includes #include "CoinList.h" #include "Pokemod.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 CoinList* 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 CoinList* parent, const int id) : Object("CoinListObject", parent, id) { *this = object; } CoinListObject::CoinListObject(const QDomElement& xml, const CoinList* parent, const int id) : Object("CoinListObject", parent, id) { load(xml, id); } void CoinListObject::validate() { TEST(setType, type); TEST(setObject, object); TEST(setAmount, amount); } 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) { if (End <= type) { emit(error(bounds("type"))); return; } m_type = type; m_object = INT_MAX; emit(changed()); } void CoinListObject::setObject(const int object) { if (((Item == m_type) && (static_cast(pokemod())->itemIndex(object) == INT_MAX)) || ((Species == m_type) && (static_cast(pokemod())->speciesIndex(object) == INT_MAX))) { emit(error(bounds("object"))); return; } m_object = object; emit(changed()); } void CoinListObject::setAmount(const int amount) { if (!amount || ((Species == m_type) && (1 < amount))) { emit(error(bounds("amount"))); return; } m_amount = amount; emit(changed()); } void CoinListObject::setCost(const int cost) { m_cost = cost; emit(changed()); } 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; }