/* * Copyright 2007-2008 Ben Boeckel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ // Header include #include "MapWarp.h" // Sigmod includes #include "Macros.h" #include "Map.h" #include "Sigmod.h" const QStringList Sigmod::MapWarp::TypeStr = QStringList() << "Door" << "Warp" << "Hole" << "Boundary"; Sigmod::MapWarp::MapWarp(const MapWarp& warp) : Object(warp.parent(), warp.id()) { *this = warp; } Sigmod::MapWarp::MapWarp(const Map* parent, const int id) : Object(parent, id), m_name(""), m_coordinate(0, 0), m_type(Door), m_toMap(INT_MAX), m_toWarp(INT_MAX), m_script("", "") { } Sigmod::MapWarp::MapWarp(const MapWarp& warp, const Map* parent, const int id) : Object(parent, id) { *this = warp; } Sigmod::MapWarp::MapWarp(const QDomElement& xml, const Map* parent, const int id) : Object(parent, id) { LOAD_ID(); load(xml); } void Sigmod::MapWarp::validate() { TEST_BEGIN(); if (m_name.isEmpty()) emit(error("Name is empty")); TEST(setToMap, toMap); TEST(setToWarp, toWarp); TEST_END(); } void Sigmod::MapWarp::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(name); LOAD(coordinate); LOAD(type); LOAD(toMap); LOAD(toWarp); LOAD(script); } QDomElement Sigmod::MapWarp::save() const { SAVE_CREATE(); SAVE(name); SAVE(coordinate); SAVE(type); SAVE(toMap); SAVE(toWarp); SAVE(script); return xml; } void Sigmod::MapWarp::setName(const QString& name) { CHECK(name); } void Sigmod::MapWarp::setCoordinate(const QPoint& coordinate) { if ((qobject_cast(parent())->width() <= coordinate.x()) || (qobject_cast(parent())->height() <= coordinate.y())) emit(error(bounds("coordinate"))); else CHECK(coordinate); } void Sigmod::MapWarp::setType(const Type type) { CHECK(type); } void Sigmod::MapWarp::setToMap(const int toMap) { if (qobject_cast(sigmod())->mapIndex(toMap) == INT_MAX) emit(error(bounds("toMap"))); else CHECK(toMap); } void Sigmod::MapWarp::setToWarp(const int toWarp) { if (qobject_cast(sigmod())->mapIndex(m_toMap) == INT_MAX) emit(error(bounds("toMap"))); else if (qobject_cast(sigmod())->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) emit(error(bounds("toWarp"))); else CHECK(toWarp); } void Sigmod::MapWarp::setScript(const Script& script) { CHECK(script); } QString Sigmod::MapWarp::name() const { return m_name; } QPoint Sigmod::MapWarp::coordinate() const { return m_coordinate; } Sigmod::MapWarp::Type Sigmod::MapWarp::type() const { return m_type; } int Sigmod::MapWarp::toMap() const { return m_toMap; } int Sigmod::MapWarp::toWarp() const { return m_toWarp; } Sigmod::Script Sigmod::MapWarp::script() const { return m_script; } Sigmod::MapWarp& Sigmod::MapWarp::operator=(const MapWarp& rhs) { if (this == &rhs) return *this; COPY(name); COPY(coordinate); COPY(type); COPY(toMap); COPY(toWarp); COPY(script); return *this; }