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/CoinList.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/CoinList.cpp')
| -rw-r--r-- | pokemod/CoinList.cpp | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/pokemod/CoinList.cpp b/pokemod/CoinList.cpp index 0b0ff46b..b6349c50 100644 --- a/pokemod/CoinList.cpp +++ b/pokemod/CoinList.cpp @@ -42,16 +42,15 @@ CoinList::CoinList(const Pokemod* pokemod, const CoinList& coinList, const int i *this = coinList; } -CoinList::CoinList(const Pokemod* pokemod, const QString& fileName, const int id) : +CoinList::CoinList(const Pokemod* pokemod, const QDomElement& xml, const int id) : Object("CoinList", pokemod, id) { - load(fileName, id); + load(xml, id); } CoinList::~CoinList() { - while (objectCount()) - deleteObject(0); + clear(); } bool CoinList::validate() const @@ -113,36 +112,21 @@ bool CoinList::validate() const return valid; } -void CoinList::load(const QString& fileName, int id) throw(Exception) +void CoinList::load(const QDomElement& xml, int id) { - Ini ini(fileName); - if (id == INT_MAX) - ini.getValue("id", id); - setId(id); - ini.getValue("name", m_name); - ini.getValue("value", m_value, 0); - QStringList path = pokemod()->path().split('/'); - path.removeLast(); - QDir fdir(path.join("/")); - while (objectCount()) - deleteObject(0); - if (fdir.cd("item")) - { - QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); - foreach (QString file, files) - newObject(file); - } + LOAD_ID(); + LOAD(QString, name); + LOAD(int, value); + LOAD_SUB(newObject, CoinListObject); } -void CoinList::save() const throw(Exception) +QDomElement CoinList::save() const { - Ini ini; - ini.addField("id", id()); - ini.addField("name", m_name); - ini.addField("value", m_value); - ini.save(QString("%1/coinlist/%2/data.pini").arg(pokemod()->path()).arg(m_name)); - foreach (CoinListObject* object, m_objects) - object->save(m_name); + SAVE_CREATE(); + SAVE(QString, name); + SAVE(int, value); + SAVE_SUB(CoinListObject, objects); + return xml; } void CoinList::setName(const QString& name) @@ -181,14 +165,14 @@ int CoinList::value() const const CoinListObject* CoinList::object(const int index) const throw(IndexException) { if (objectCount() <= index) - throw(IndexException(className())); + error<IndexException>("object"); return m_objects.at(index); } CoinListObject* CoinList::object(const int index) throw(IndexException) { if (objectCount() <= index) - throw(IndexException(className())); + error<IndexException>("object"); return m_objects[index]; } @@ -223,9 +207,9 @@ CoinListObject* CoinList::newObject() return m_objects[objectCount() - 1]; } -CoinListObject* CoinList::newObject(const QString& fileName) +CoinListObject* CoinList::newObject(const QDomElement& xml) { - m_objects.append(new CoinListObject(pokemod(), fileName, objectId())); + m_objects.append(new CoinListObject(pokemod(), xml, objectId())); return m_objects[objectCount() - 1]; } @@ -238,7 +222,7 @@ CoinListObject* CoinList::newObject(const CoinListObject& object) void CoinList::deleteObject(const int index) throw(IndexException) { if (objectCount() <= index) - throw(IndexException(className())); + error<IndexException>("object"); delete m_objects[index]; m_objects.removeAt(index); } @@ -260,10 +244,8 @@ CoinList& CoinList::operator=(const CoinList& rhs) { if (this == &rhs) return *this; - m_name = rhs.m_name; - while (objectCount()) - deleteObject(0); - foreach (CoinListObject* object, rhs.m_objects) - m_objects.append(new CoinListObject(pokemod(), *object, object->id())); + clear(); + COPY(name); + COPY_SUB(CoinListObject, objects); return *this; } |
