diff options
Diffstat (limited to 'pokemod/Tile.cpp')
-rw-r--r-- | pokemod/Tile.cpp | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/pokemod/Tile.cpp b/pokemod/Tile.cpp index 7f9e319e..11043882 100644 --- a/pokemod/Tile.cpp +++ b/pokemod/Tile.cpp @@ -28,7 +28,6 @@ const QStringList Tile::ForceStr = QStringList() << "Slip" << "Stop" << "Force" Tile::Tile(const Pokemod* par, const int _id) : Object("Tile", par, _id), name(""), - pic(""), wildChance(1, 1), hmType(-1), under(-1), @@ -46,8 +45,7 @@ Tile::Tile(const Pokemod* par, const Tile& t, const int _id) : } Tile::Tile(const Pokemod* par, const QString& fname, const int _id) : - Object("Tile", par, _id), - pic("") + Object("Tile", par, _id) { load(fname, _id); } @@ -61,7 +59,7 @@ bool Tile::validate() const pokemod->validationMsg("Name is not defined"); valid = false; } - if (!QFile::exists(QString("%1/image/tile/%2.png").arg(pokemod->getPath()).arg(pic))) + if (!QFile::exists(getPic())) { pokemod->validationMsg("Cannot find tile image"); valid = false; @@ -112,7 +110,6 @@ void Tile::load(const QString& fname, const int _id) throw(Exception) int i; int j; ini.getValue("name", name); - ini.getValue("pic", pic); ini.getValue("from-up", from[D_Up], false); ini.getValue("from-down", from[D_Down], false); ini.getValue("from-left", from[D_Left], false); @@ -131,7 +128,6 @@ void Tile::save() const throw(Exception) Ini ini; ini.addField("id", id); ini.addField("name", name); - ini.addField("pic", pic); ini.addField("from-up", from[D_Up]); ini.addField("from-down", from[D_Down]); ini.addField("from-left", from[D_Left]); @@ -150,11 +146,13 @@ void Tile::setName(const QString& n) name = n; } -void Tile::setPic(const QString& p) throw(OpenException) +void Tile::setPic(const QString& fname) throw(Exception) { - if (!QFile::exists(QString("%1/image/tile/%2.png").arg(pokemod->getPath()).arg(p))) - throw(OpenException(className, QString("%1/image/tile/%2.png").arg(pokemod->getPath()).arg(p))); - pic = p; + QFile file(getPic()); + if (file.exists() && !file.remove()) + throw(RemoveException(className, file.fileName())); + if (!QFile::copy(fname, getPic())) + throw(SaveException(className, file.fileName())); } void Tile::setFrom(const int d, const bool f) throw(BoundsException) @@ -225,7 +223,7 @@ QString Tile::getName() const QString Tile::getPic() const { - return pic; + return QString("%1/tile/%2.png").arg(pokemod->getPath()).arg(name); } bool Tile::getFrom(const int d) const throw(BoundsException) @@ -265,7 +263,6 @@ Tile& Tile::operator=(const Tile& rhs) if (this == &rhs) return *this; name = rhs.name; - pic = rhs.pic; for (int i = 0; i < D_End; ++i) from[i] = rhs.from[i]; wildChance = rhs.wildChance; |