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/MapTrainer.cpp | |
| parent | 12d5161318a4d8d781f896812f5a95fa7b46d8a8 (diff) | |
| download | sigen-e1b5d7bc705810ac15ed36924617af52abdc8e81.tar.gz sigen-e1b5d7bc705810ac15ed36924617af52abdc8e81.tar.xz sigen-e1b5d7bc705810ac15ed36924617af52abdc8e81.zip | |
[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/MapTrainer.cpp')
| -rw-r--r-- | pokemod/MapTrainer.cpp | 147 |
1 files changed, 60 insertions, 87 deletions
diff --git a/pokemod/MapTrainer.cpp b/pokemod/MapTrainer.cpp index ccd0d12d..b1db08d3 100644 --- a/pokemod/MapTrainer.cpp +++ b/pokemod/MapTrainer.cpp @@ -48,16 +48,15 @@ MapTrainer::MapTrainer(const Pokemod* pokemod, const MapTrainer& trainer, const *this = trainer; } -MapTrainer::MapTrainer(const Pokemod* pokemod, const QString& fileName, const int id) : +MapTrainer::MapTrainer(const Pokemod* pokemod, const QDomElement& xml, const int id) : Object("MapTrainer", pokemod, id) { - load(fileName, id); + load(xml, id); } MapTrainer::~MapTrainer() { - while (teamMemberCount()) - deleteTeamMember(0); + clear(); } bool MapTrainer::validate() const @@ -97,7 +96,7 @@ bool MapTrainer::validate() const if (teamMemberCount()) { QMap<int, bool> idChecker; - foreach (MapTrainerTeamMember* teamMember, m_teamMembers) + foreach (MapTrainerTeamMember* teamMember, m_teamMember) { if (!teamMember->isValid()) valid = false; @@ -114,58 +113,34 @@ bool MapTrainer::validate() const return valid; } -void MapTrainer::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("trainerClass", m_trainerClass); - ini.getValue("coordinate-x", i, 0); - ini.getValue("coordinate-y", j, 0); - m_coordinate.set(i, j); - ini.getValue("sight", m_sight, 0); - ini.getValue("direction", m_direction); - ini.getValue("numFight", m_numFight, 1); - ini.getValue("appearFlag-f", i, 0); - ini.getValue("appearFlag-s", j, 0); - m_appearFlag.set(i, j); - ini.getValue("dialog", m_dialog); - ini.getValue("leadTeamMember", m_leadTeamMember); - QStringList path = pokemod()->path().split('/'); - path.removeLast(); - QDir fdir(path.join("/")); - while (teamMemberCount()) - deleteTeamMember(0); - if (fdir.cd("team")) - { - QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); - foreach (QString file, files) - newTeamMember(file); - } +void MapTrainer::load(const QDomElement& xml, int id) +{ + LOAD_ID(); + LOAD(QString, name); + LOAD(int, trainerClass); + LOAD(Point, coordinate); + LOAD(int, sight); + LOAD(int, direction); + LOAD(int, numFight); + LOAD(Flag, appearFlag); + LOAD(int, dialog); + LOAD_SUB(newTeamMember, MapTrainerTeamMember); + LOAD(int, leadTeamMember); } -void MapTrainer::save(const QString& map) const throw(Exception) +QDomElement MapTrainer::save() const { - Ini ini; - ini.addField("id", id()); - ini.addField("name", m_name); - ini.addField("trainerClass", m_trainerClass); - ini.addField("coordinate-x", m_coordinate.x()); - ini.addField("coordinate-y", m_coordinate.y()); - ini.addField("sight", m_sight); - ini.addField("direction", m_direction); - ini.addField("numFight", m_numFight); - ini.addField("appearFlag-f", m_appearFlag.flag()); - ini.addField("appearFlag-s", m_appearFlag.status()); - ini.addField("dialog", m_dialog); - ini.addField("leadTeamMember", m_leadTeamMember); - ini.save(QString("%1/map/%2/trainer/%3/data.pini").arg(pokemod()->path()).arg(map).arg(m_name)); - foreach (MapTrainerTeamMember* teamMember, m_teamMembers) - teamMember->save(map, m_name); + SAVE_CREATE(); + SAVE(QString, name); + SAVE(int, trainerClass); + SAVE(Point, coordinate); + SAVE(int, sight); + SAVE(int, direction); + SAVE(int, numFight); + SAVE(Flag, appearFlag); + SAVE(int, dialog); + SAVE_SUB(MapTrainerTeamMember, teamMember); + return xml; } void MapTrainer::setName(const QString& name) @@ -180,9 +155,9 @@ void MapTrainer::setTrainerClass(const int trainerClass) throw(BoundsException) m_trainerClass = trainerClass; } -void MapTrainer::setCoordinate(const int x, const int y) +void MapTrainer::setCoordinate(const Point& coordinate) { - m_coordinate.set(x, y); + m_coordinate = coordinate; } void MapTrainer::setSight(const int sight) @@ -204,9 +179,9 @@ void MapTrainer::setNumFight(const int numFight) throw(BoundsException) m_numFight = numFight; } -void MapTrainer::setAppearFlag(const int flag, const int status) +void MapTrainer::setAppearFlag(const Flag& appearFlag) { - m_appearFlag.set(flag, status); + m_appearFlag = appearFlag; } void MapTrainer::setDialog(const int dialog) throw(BoundsException) @@ -271,15 +246,15 @@ int MapTrainer::leadTeamMember() const const MapTrainerTeamMember* MapTrainer::teamMember(const int index) const throw(IndexException) { if (teamMemberCount() <= index) - throw(IndexException(className())); - return m_teamMembers.at(index); + error<IndexException>("team member"); + return m_teamMember.at(index); } MapTrainerTeamMember* MapTrainer::teamMember(const int index) throw(IndexException) { if (teamMemberCount() <= index) - throw(IndexException(className())); - return m_teamMembers[index]; + error<IndexException>("team member"); + return m_teamMember[index]; } const MapTrainerTeamMember* MapTrainer::teamMemberById(const int id) const throw(IndexException) @@ -296,7 +271,7 @@ int MapTrainer::teamMemberIndex(const int id) const { for (int i = 0; i < teamMemberCount(); ++i) { - if (m_teamMembers[i]->id() == id) + if (m_teamMember[i]->id() == id) return i; } return INT_MAX; @@ -304,33 +279,33 @@ int MapTrainer::teamMemberIndex(const int id) const int MapTrainer::teamMemberCount() const { - return m_teamMembers.size(); + return m_teamMember.size(); } MapTrainerTeamMember* MapTrainer::newTeamMember() { - m_teamMembers.append(new MapTrainerTeamMember(pokemod(), newTeamMemberId())); - return m_teamMembers[teamMemberCount() - 1]; + m_teamMember.append(new MapTrainerTeamMember(pokemod(), newTeamMemberId())); + return m_teamMember[teamMemberCount() - 1]; } -MapTrainerTeamMember* MapTrainer::newTeamMember(const QString& fileName) +MapTrainerTeamMember* MapTrainer::newTeamMember(const QDomElement& xml) { - m_teamMembers.append(new MapTrainerTeamMember(pokemod(), fileName, newTeamMemberId())); - return m_teamMembers[teamMemberCount() - 1]; + m_teamMember.append(new MapTrainerTeamMember(pokemod(), xml, newTeamMemberId())); + return m_teamMember[teamMemberCount() - 1]; } MapTrainerTeamMember* MapTrainer::newTeamMember(const MapTrainerTeamMember& teamMember) { - m_teamMembers.append(new MapTrainerTeamMember(pokemod(), teamMember, newTeamMemberId())); - return m_teamMembers[teamMemberCount() - 1]; + m_teamMember.append(new MapTrainerTeamMember(pokemod(), teamMember, newTeamMemberId())); + return m_teamMember[teamMemberCount() - 1]; } void MapTrainer::deleteTeamMember(const int index) throw(IndexException) { if (teamMemberCount() <= index) - throw(IndexException(className())); - delete m_teamMembers[index]; - m_teamMembers.removeAt(index); + error<IndexException>("team member"); + delete m_teamMember[index]; + m_teamMember.removeAt(index); } void MapTrainer::deleteTeamMemberById(const int id) throw(IndexException) @@ -350,18 +325,16 @@ MapTrainer& MapTrainer::operator=(const MapTrainer& rhs) { if (this == &rhs) return *this; - m_name = rhs.m_name; - m_trainerClass = rhs.m_trainerClass; - m_coordinate = rhs.m_coordinate; - m_sight = rhs.m_sight; - m_direction = rhs.m_direction; - m_numFight = rhs.m_numFight; - m_appearFlag = rhs.m_appearFlag; - m_dialog = rhs.m_dialog; - m_leadTeamMember = rhs.m_leadTeamMember; - while (teamMemberCount()) - deleteTeamMember(0); - foreach (MapTrainerTeamMember* teamMember, rhs.m_teamMembers) - m_teamMembers.append(new MapTrainerTeamMember(pokemod(), *teamMember, teamMember->id())); + clear(); + COPY(name); + COPY(trainerClass); + COPY(coordinate); + COPY(sight); + COPY(direction); + COPY(numFight); + COPY(appearFlag); + COPY(dialog); + COPY(leadTeamMember); + COPY_SUB(MapTrainerTeamMember, teamMember); return *this; } |
