diff options
Diffstat (limited to 'sigmod/MapWarp.cpp')
| -rw-r--r-- | sigmod/MapWarp.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/sigmod/MapWarp.cpp b/sigmod/MapWarp.cpp index bd4934b6..e0482f14 100644 --- a/sigmod/MapWarp.cpp +++ b/sigmod/MapWarp.cpp @@ -34,7 +34,7 @@ Sigmod::MapWarp::MapWarp(const MapWarp& warp) : Sigmod::MapWarp::MapWarp(const Map* parent, const int id) : Object(parent, id), m_name(""), - m_coordinate(0, 0), + m_area(0, 0, 32, 32), m_type(Door), m_toMap(INT_MAX), m_toWarp(INT_MAX), @@ -60,6 +60,7 @@ void Sigmod::MapWarp::validate() TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); + TEST(setArea, area); TEST(setToMap, toMap); TEST(setToWarp, toWarp); TEST_END(); @@ -69,7 +70,7 @@ void Sigmod::MapWarp::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(name); - LOAD(coordinate); + LOAD(area); LOAD(type); LOAD(toMap); LOAD(toWarp); @@ -80,7 +81,7 @@ QDomElement Sigmod::MapWarp::save() const { SAVE_CREATE(); SAVE(name); - SAVE(coordinate); + SAVE(area); SAVE(type); SAVE(toMap); SAVE(toWarp); @@ -93,12 +94,15 @@ void Sigmod::MapWarp::setName(const QString& name) CHECK(name); } -void Sigmod::MapWarp::setCoordinate(const QPoint& coordinate) +void Sigmod::MapWarp::setArea(const QRect& area) { - if ((qobject_cast<const Map*>(parent())->width() <= coordinate.x()) || (qobject_cast<const Map*>(parent())->height() <= coordinate.y())) - emit(error(bounds("coordinate"))); + const Map* map = qobject_cast<const Map*>(parent()); + if ((map->width() <= area.x()) || (map->height() <= area.y())) + emit(error(bounds("area"))); + else if ((area.width() <= 0) || (area.height() <= 0)) + emit(error(bounds("area"))); else - CHECK(coordinate); + CHECK(area); } void Sigmod::MapWarp::setType(const Type type) @@ -108,7 +112,7 @@ void Sigmod::MapWarp::setType(const Type type) void Sigmod::MapWarp::setToMap(const int toMap) { - if (qobject_cast<const Sigmod*>(sigmod())->mapIndex(toMap) == INT_MAX) + if (!sigmod()->mapById(toMap)) emit(error(bounds("toMap"))); else CHECK(toMap); @@ -116,9 +120,10 @@ void Sigmod::MapWarp::setToMap(const int toMap) void Sigmod::MapWarp::setToWarp(const int toWarp) { - if (qobject_cast<const Sigmod*>(sigmod())->mapIndex(m_toMap) == INT_MAX) + const Map* map = sigmod()->mapById(m_toMap); + if (!map) emit(error(bounds("toMap"))); - else if (qobject_cast<const Sigmod*>(sigmod())->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) + else if (!map->warpById(toWarp)) emit(error(bounds("toWarp"))); else CHECK(toWarp); @@ -134,9 +139,9 @@ QString Sigmod::MapWarp::name() const return m_name; } -QPoint Sigmod::MapWarp::coordinate() const +QRect Sigmod::MapWarp::area() const { - return m_coordinate; + return m_area; } Sigmod::MapWarp::Type Sigmod::MapWarp::type() const @@ -164,7 +169,7 @@ Sigmod::MapWarp& Sigmod::MapWarp::operator=(const MapWarp& rhs) if (this == &rhs) return *this; COPY(name); - COPY(coordinate); + COPY(area); COPY(type); COPY(toMap); COPY(toWarp); |
