diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-04-15 18:57:00 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-04-15 18:57:00 +0000 |
| commit | e1b5d7bc705810ac15ed36924617af52abdc8e81 (patch) | |
| tree | 0dae5af4e2737372ec479bb9ccdd2201edf684a8 /pokemod/Move.cpp | |
| parent | 12d5161318a4d8d781f896812f5a95fa7b46d8a8 (diff) | |
[FIX] Object::mid -> m_id
[FIX] XML is now used
[FIX] Images are stored in the XML file and classes rather than relying on external images
[FIX] Frac no longer keeps track of its type; the class should do it
[ADD] pokemod/Object.cpp
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@97 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Move.cpp')
| -rw-r--r-- | pokemod/Move.cpp | 168 |
1 files changed, 77 insertions, 91 deletions
diff --git a/pokemod/Move.cpp b/pokemod/Move.cpp index d91eda87..490c8eca 100644 --- a/pokemod/Move.cpp +++ b/pokemod/Move.cpp @@ -55,16 +55,15 @@ Move::Move(const Pokemod* pokemod, const Move& move, const int id) : *this = move; } -Move::Move(const Pokemod* pokemod, const QString& fileName, const int id) : +Move::Move(const Pokemod* pokemod, const QDomElement& xml, const int id) : Object("Move", pokemod, id) { - load(fileName, id); + load(xml, id); } Move::~Move() { - while (effectCount()) - deleteEffect(0); + clear(); } bool Move::validate() const @@ -121,67 +120,46 @@ bool Move::validate() const return valid; } -void Move::load(const QString& fileName, int id) throw(Exception) -{ - Ini ini(fileName); - if (id == INT_MAX) - ini.getValue("id", id); - setId(id); - int i; - int j; - ini.getValue("name", m_name); - ini.getValue("accuracy-n", i, 1); - ini.getValue("accuracy-d", j, 1); - m_accuracy.set(i, j); - ini.getValue("power", m_power, 0); - ini.getValue("type", m_type); - ini.getValue("special", m_special, false); - ini.getValue("powerPoints", m_powerPoints, 1); - ini.getValue("target", m_target); - ini.getValue("numTargets", m_numTargets, 0); - ini.getValue("targetChoice", m_targetChoice); - ini.getValue("ignoreAccuracy", m_ignoreAccuracy, false); - ini.getValue("canFlinch", m_canFlinch, false); - ini.getValue("canRandom", m_canRandom, false); - ini.getValue("canSnatch", m_canSnatch, false); - ini.getValue("sound", m_sound, false); - ini.getValue("description", m_description, ""); - QStringList path = pokemod()->path().split('/'); - path.removeLast(); - QDir fdir(path.join("/")); - while (effectCount()) - deleteEffect(0); - if (fdir.cd("effect")) - { - QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); - foreach (QString file, files) - newEffect(file); - } -} - -void Move::save() const throw(Exception) -{ - Ini ini; - ini.addField("id", id()); - ini.addField("name", m_name); - ini.addField("accuracy-n", m_accuracy.numerator()); - ini.addField("accuracy-d", m_accuracy.denominator()); - ini.addField("power", m_power); - ini.addField("type", m_type); - ini.addField("special", m_special); - ini.addField("powerPoints", m_powerPoints); - ini.addField("target", m_target); - ini.addField("numTargets", m_numTargets); - ini.addField("targetChoice", m_targetChoice); - ini.addField("ignoreAccuracy", m_ignoreAccuracy); - ini.addField("canFlinch", m_canFlinch); - ini.addField("canRandom", m_canRandom); - ini.addField("canSnatch", m_canSnatch); - ini.addField("sound", m_sound); - ini.addField("description", m_description); - ini.save(QString("%1/move/%2/data.pini").arg(pokemod()->path()).arg(m_name)); - foreach (MoveEffect* effect, m_effects) - effect->save(m_name); +void Move::load(const QDomElement& xml, int id) +{ + LOAD_ID(); + LOAD(QString, name); + LOAD(Frac, accuracy); + LOAD(int, power); + LOAD(int, type); + LOAD(bool, special); + LOAD(int, powerPoints); + LOAD(int, target); + LOAD(int, targetChoice); + LOAD(bool, ignoreAccuracy); + LOAD(bool, canFlinch); + LOAD(bool, canRandom); + LOAD(bool, canSnatch); + LOAD(bool, sound); + LOAD(QString, description); + LOAD_SUB(newEffect, effects); +} + +QDomElement Move::save() const +{ + SAVE_CREATE(); + SAVE(QString, name); + SAVE(Frac, accuracy); + SAVE(int, power); + SAVE(int, type); + SAVE(bool, special); + SAVE(int, powerPoints); + SAVE(int, target); + SAVE(int, numTargets); + SAVE(int, targetChoice); + SAVE(bool, ignoreAccuracy); + SAVE(bool, canFlinch); + SAVE(bool, canRandom); + SAVE(bool, canSnatch); + SAVE(bool, sound); + SAVE(QString, description); + SAVE_SUB(MoveEffect, effects); + return xml; } void Move::setName(const QString& name) @@ -189,9 +167,14 @@ void Move::setName(const QString& name) m_name = name; } -void Move::setAccuracy(const int n, const int d) throw(Exception) +void Move::setAccuracy(const Frac& accuracy) throw(Exception) +{ + m_accuracy = accuracy; +} + +void Move::setPower(const int power) { - m_accuracy.set(n, d); + m_power = power; } void Move::setType(const int type) throw(BoundsException) @@ -274,6 +257,11 @@ Frac Move::accuracy() const return m_accuracy; } +int Move::power() const +{ + return m_power; +} + int Move::type() const { return m_type; @@ -337,14 +325,14 @@ QString Move::description() const const MoveEffect* Move::effect(const int index) const throw(IndexException) { if (effectCount() <= index) - throw(IndexException(className())); + error<IndexException>("effect"); return m_effects.at(index); } MoveEffect* Move::effect(const int index) throw(IndexException) { if (effectCount() <= index) - throw(IndexException(className())); + error<IndexException>("effect"); return m_effects[index]; } @@ -379,9 +367,9 @@ MoveEffect* Move::newEffect() return m_effects[effectCount() - 1]; } -MoveEffect* Move::newEffect(const QString& fileName) +MoveEffect* Move::newEffect(const QDomElement& xml) { - m_effects.append(new MoveEffect(pokemod(), fileName, newEffectId())); + m_effects.append(new MoveEffect(pokemod(), xml, newEffectId())); return m_effects[effectCount() - 1]; } @@ -394,7 +382,7 @@ MoveEffect* Move::newEffect(const MoveEffect& effect) void Move::deleteEffect(const int index) throw(IndexException) { if (effectCount() <= index) - throw(IndexException(className())); + error<IndexException>("effect"); delete m_effects[index]; m_effects.removeAt(index); } @@ -416,24 +404,22 @@ Move& Move::operator=(const Move& rhs) { if (this == &rhs) return *this; - m_name = rhs.m_name; - m_accuracy = rhs.m_accuracy; - m_power = rhs.m_power; - m_type = rhs.m_type; - m_special = rhs.m_special; - m_powerPoints = rhs.m_powerPoints; - m_target = rhs.m_target; - m_numTargets = rhs.m_numTargets; - m_targetChoice = rhs.m_targetChoice; - m_ignoreAccuracy = rhs.m_ignoreAccuracy; - m_canFlinch = rhs.m_canFlinch; - m_canRandom = rhs.m_canRandom; - m_canSnatch = rhs.m_canSnatch; - m_sound = rhs.m_sound; - m_description = rhs.m_description; - while (effectCount()) - deleteEffect(0); - foreach (MoveEffect* effect, rhs.m_effects) - m_effects.append(new MoveEffect(pokemod(), *effect, effect->id())); + clear(); + COPY(name); + COPY(accuracy); + COPY(power); + COPY(type); + COPY(special); + COPY(powerPoints); + COPY(target); + COPY(numTargets); + COPY(targetChoice); + COPY(ignoreAccuracy); + COPY(canFlinch); + COPY(canRandom); + COPY(canSnatch); + COPY(sound); + COPY(description); + COPY_SUB(MoveEffect, effects); return *this; } |
