/* * Copyright 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 "Trainer.h" // Pokemod includes #include "Pokemod.h" // Qt includes #include Trainer::Trainer(const Trainer& trainer) : Object("Trainer", trainer.parent(), trainer.id()) { *this = trainer; } Trainer::Trainer(const Pokemod* parent, const int id) : Object("Trainer", parent, id), m_name(""), m_moneyFactor(0), m_skin(192, 128) { } Trainer::Trainer(const Trainer& trainer, const Pokemod* parent, const int id) : Object("Trainer", parent, id) { *this = trainer; } Trainer::Trainer(const QDomElement& xml, const Pokemod* parent, const int id) : Object("Trainer", parent, id) { load(xml, id); } void Trainer::validate() { if (m_name.isEmpty()) emit(error("Name is empty")); TEST(setMoneyFactor, moneyFactor); TEST(setSkin, skin); } void Trainer::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(QString, name); LOAD(int, moneyFactor); LOAD(QPixmap, skin); } QDomElement Trainer::save() const { SAVE_CREATE(); SAVE(QString, name); SAVE(int, moneyFactor); SAVE(QPixmap, skin); return xml; } void Trainer::setName(const QString& name) { m_name = name; emit(changed()); } void Trainer::setMoneyFactor(const int moneyFactor) { if (moneyFactor < 0) { emit(error(bounds("moneyFactor"))); return; } m_moneyFactor = moneyFactor; emit(changed()); } void Trainer::setSkin(const QPixmap& skin) { if (skin.size() != QSize(192, 128)) { emit(error(size("skin"))); return; } m_skin = skin; emit(changed()); } // void Trainer::setAi(const QString& fileName) // { // QFile file(ai()); // if (file.exists() && !file.remove()) // throw(ReplaceException(className(), file.fileName())); // if (!QFile::copy(fileName, ai())) // throw(SaveException(className(), file.fileName())); // } QString Trainer::name() const { return m_name; } int Trainer::moneyFactor() const { return m_moneyFactor; } QPixmap Trainer::skin() const { return m_skin; } // QString Trainer::ai() const // { // return QString("%1/trainer/%2/ai.pai").arg(static_cast(pokemod())->path()).arg(m_name); // } Trainer& Trainer::operator=(const Trainer& rhs) { if (this == &rhs) return *this; COPY(name); COPY(moneyFactor); COPY(skin); return *this; }