diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-13 01:32:22 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-13 01:32:22 +0000 |
| commit | 571f40d02ec5322b7aa62e8b0f7d37ba538a9a25 (patch) | |
| tree | 5d5c7d9c250369d3acdc5f05f1eeca4aede66cb8 /pokemod/Pokemod.cpp | |
| parent | e11ae3d4907f0ce39b96ba6b29442be05f99b59c (diff) | |
| download | sigen-571f40d02ec5322b7aa62e8b0f7d37ba538a9a25.tar.gz sigen-571f40d02ec5322b7aa62e8b0f7d37ba538a9a25.tar.xz sigen-571f40d02ec5322b7aa62e8b0f7d37ba538a9a25.zip | |
[ADD] Added Sound class and related code
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@125 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Pokemod.cpp')
| -rw-r--r-- | pokemod/Pokemod.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp index 90c064bf..83c25cb2 100644 --- a/pokemod/Pokemod.cpp +++ b/pokemod/Pokemod.cpp @@ -30,6 +30,7 @@ #include "Map.h" #include "Move.h" #include "Nature.h" +#include "Sound.h" #include "Species.h" #include "Store.h" #include "Tile.h" @@ -270,6 +271,20 @@ void Pokemod::validate() idChecker.clear(); nameChecker.clear(); } + if (!soundCount()) + emit(error("There are no sounds")); + foreach (Sound* sound, m_sounds) + { + sound->validate(); + if (idChecker.contains(sound->id())) + emit(error(subclass("sound", sound->id()))); + idChecker.insert(sound->id()); + if (nameChecker.contains(sound->name())) + emit(error(subclass("sound", sound->name()))); + nameChecker.insert(sound->name()); + } + idChecker.clear(); + nameChecker.clear(); if (!speciesCount()) emit(error("There are no species")); foreach (Species* species, m_species) @@ -385,6 +400,7 @@ void Pokemod::load(const QDomElement& xml, const int) LOAD_SUB(newMap, Map); LOAD_SUB(newMove, Move); LOAD_SUB(newNature, Nature); + LOAD_SUB(newSound, Sound); LOAD_SUB(newSpecies, Species); LOAD_SUB(newStore, Store); LOAD_SUB(newTile, Tile); @@ -423,6 +439,7 @@ QDomElement Pokemod::save() const SAVE_SUB(Map, maps); SAVE_SUB(Move, moves); SAVE_SUB(Nature, natures); + SAVE_SUB(Sound, sounds); SAVE_SUB(Species, species); SAVE_SUB(Store, stores); SAVE_SUB(Tile, tiles); @@ -1543,6 +1560,87 @@ int Pokemod::newNatureId() const return i; } +const Sound* Pokemod::sound(const int index) const +{ + if (soundCount() <= index) + return NULL; + return m_sounds.at(index); +} + +Sound* Pokemod::sound(const int index) +{ + if (soundCount() <= index) + return NULL; + return m_sounds[index]; +} + +const Sound* Pokemod::soundById(const int id) const +{ + return sound(soundIndex(id)); +} + +Sound* Pokemod::soundById(const int id) +{ + return sound(soundIndex(id)); +} + +int Pokemod::soundIndex(const int id) const +{ + for (int i = 0; i < soundCount(); ++i) + { + if (m_sounds[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::soundCount() const +{ + return m_sounds.size(); +} + +Sound* Pokemod::newSound() +{ + return newSound(new Sound(this, newSoundId())); +} + +Sound* Pokemod::newSound(const QDomElement& xml) +{ + return newSound(new Sound(xml, this, newSoundId())); +} + +Sound* Pokemod::newSound(const Sound& sound) +{ + return newSound(new Sound(sound, this, newSoundId())); +} + +Sound* Pokemod::newSound(Sound* sound) +{ + m_sounds.append(sound); + return sound; +} + +void Pokemod::deleteSound(const int index) +{ + if (soundCount() <= index) + return; + delete m_sounds[index]; + m_sounds.removeAt(index); +} + +void Pokemod::deleteSoundById(const int id) +{ + deleteSound(soundIndex(id)); +} + +int Pokemod::newSoundId() const +{ + int i = 0; + while ((i < soundCount()) && (soundIndex(i) != INT_MAX)) + ++i; + return i; +} + const Species* Pokemod::species(const int index) const { if (speciesCount() <= index) @@ -2068,6 +2166,7 @@ Pokemod& Pokemod::operator=(const Pokemod& rhs) COPY_SUB(Map, maps); COPY_SUB(Move, moves); COPY_SUB(Nature, natures); + COPY_SUB(Sound, sounds); COPY_SUB(Species, species); COPY_SUB(Store, stores); COPY_SUB(Tile, tiles); @@ -2102,6 +2201,8 @@ void Pokemod::clear() deleteMove(0); while (natureCount()) deleteNature(0); + while (soundCount()) + deleteSound(0); while (speciesCount()) deleteSpecies(0); while (storeCount()) |
