diff options
Diffstat (limited to 'pokemod/Tile.cpp')
| -rw-r--r-- | pokemod/Tile.cpp | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/pokemod/Tile.cpp b/pokemod/Tile.cpp index c6e346cb..4c45f345 100644 --- a/pokemod/Tile.cpp +++ b/pokemod/Tile.cpp @@ -58,50 +58,17 @@ Tile::Tile(const QDomElement& xml, const Object* parent, const int id) : load(xml, id); } -bool Tile::validate() const -{ - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Tile \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); -// if (m_name == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Name is not defined"); -// valid = false; -// } -// if ((m_hmType == Pokemod::HM_Waterfall) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("A waterfall tile must be accessible from above and below"); -// valid = false; -// } -// else if ((m_hmType == Pokemod::HM_Whirlpool) && ((m_under == id()) || (static_cast<const Pokemod*>(pokemod())->tileIndex(m_under) == INT_MAX) || (static_cast<const Pokemod*>(pokemod())->tileById(m_under)->hmType() != Pokemod::HM_Surf) || (static_cast<const Pokemod*>(pokemod())->tileById(m_under)->hmType() != Pokemod::HM_Dive))) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid under tile"); -// valid = false; -// } -// else if ((m_hmType == Pokemod::HM_Whirlpool) && ((m_under == id()) || (static_cast<const Pokemod*>(pokemod())->tileIndex(m_under) == INT_MAX) || (static_cast<const Pokemod*>(pokemod())->tileById(m_under)->hmType() != Pokemod::HM_End))) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid under tile"); -// valid = false; -// } -// else if ((m_hmType == Pokemod::HM_RockClimb) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("A rock climb tile must be accessible from above and below"); -// valid = false; -// } -// if (m_forceType < End) -// { -// if (((m_forceType == Slip) || (m_forceType == Force) || (m_forceType == Push)) && (Pokemod::D_End <= m_forceDirection)) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid force direction"); -// valid = false; -// } -// } -// else -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid force type"); -// valid = false; -// } -// return valid; +void Tile::validate(QTextStream& stream) +{ + TEST_SETUP(); + if (m_name.isEmpty()) + error(stream, "Name is empty"); + TEST(setSprite, sprite); + TEST(setWildChance, wildChance); + TEST(setHmType, hmType); + TEST(setUnder, under); + TEST(setForceType, forceType); + TEST(setForceDirection, forceDirection); } void Tile::load(const QDomElement& xml, int id) @@ -136,62 +103,94 @@ void Tile::setName(const QString& name) m_name = name; } -void Tile::setSprite(const QPixmap& sprite) throw(SizeException) +void Tile::setSprite(const QPixmap& sprite) { if (sprite.size() != QSize(64, 64)) - error<SizeException>("sprte"); + { + sizeError("sprite"); + return; + } m_sprite = sprite; } -void Tile::setFrom(const int direction, const bool state) throw(BoundsException) +void Tile::setFrom(const int direction, const bool state) { if (Pokemod::D_End <= direction) - error<BoundsException>("direction"); + { + boundsError("direction"); + return; + } m_from[direction] = state; } -void Tile::setWildChance(const Fraction& wildChance) throw(BoundsException) +void Tile::setWildChance(const Fraction& wildChance) { if (1 < wildChance) - error<BoundsException>("wildChance"); + { + boundsError("wildChance"); + return; + } m_wildChance = wildChance; } -void Tile::setHMType(const int hmType) throw(BoundsException) +void Tile::setHmType(const int hmType) { if (Pokemod::HM_End <= hmType) - error<BoundsException>("hmType"); + { + boundsError("hmType"); + return; + } + if (((hmType == Pokemod::HM_Waterfall) || (hmType == Pokemod::HM_RockClimb)) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) + { + error("accessibility for HM type"); + return; + } m_hmType = hmType; m_under = INT_MAX; } -void Tile::setUnder(const int under) throw(Exception) +void Tile::setUnder(const int under) { if (m_hmType != INT_MAX) { if ((m_hmType != Pokemod::HM_Whirlpool) || (m_hmType != Pokemod::HM_Cut) || (m_hmType != Pokemod::HM_RockSmash)) - error<UnusedException>("under"); + { + unusedError("under"); + return; + } if ((under == id()) || (static_cast<const Pokemod*>(pokemod())->tileIndex(under) == INT_MAX)) - error<BoundsException>("under"); + { + boundsError("under"); + return; + } } m_under = under; } -void Tile::setForceType(const int forceType) throw(BoundsException) +void Tile::setForceType(const int forceType) { if (End <= forceType) - error<BoundsException>("forceType"); + { + boundsError("forceType"); + return; + } m_forceType = forceType; } -void Tile::setForceDirection(const int forceDirection) throw(Exception) +void Tile::setForceDirection(const int forceDirection) { if (m_forceType != INT_MAX) { if (m_forceType == Stop) - error<UnusedException>("forceDirection"); + { + unusedError("forceDirection"); + return; + } if (Pokemod::D_End <= forceDirection) - error<BoundsException>("forceDirection"); + { + boundsError("forceDirection"); + return; + } } m_forceDirection = forceDirection; } @@ -206,10 +205,11 @@ QPixmap Tile::sprite() const return m_sprite; } -bool Tile::from(const int direction) const throw(BoundsException) +bool Tile::from(const int direction) const { + // TODO: Message about fetching out-of-bounds if (Pokemod::D_End <= direction) - warning<BoundsException>("direction"); + return false; return m_from[direction]; } |
