/* * 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_area(0, 0, 32, 32), 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(setArea, area); TEST(setToMap, toMap); TEST(setToWarp, toWarp); TEST_END(); } void Sigmod::MapWarp::load(const QDomElement& xml) { LOAD_BEGIN(); LOAD(name); LOAD(area); LOAD(type); LOAD(toMap); LOAD(toWarp); LOAD(script); } QDomElement Sigmod::MapWarp::save() const { SAVE_CREATE(); SAVE(name); SAVE(area); SAVE(type); SAVE(toMap); SAVE(toWarp); SAVE(script); return xml; } void Sigmod::MapWarp::setName(const QString& name) { CHECK(name); } void Sigmod::MapWarp::setArea(const QRect& area) { const Map* map = qobject_cast(parent()); if ((map->width() <= area.x()) || (map->height() <= area.y())) emit(error(bounds("area", QPoint(0, 0), QPoint(map->width(), map->height()), area.topLeft()))); else if ((area.width() <= 0) || (area.height() <= 0) || ((map->width() - area.x()) < area.width()) || ((map->height() - area.y()) < area.height())) emit(error(bounds("area size", QPoint(0, 0), QPoint(map->width() - area.x(), map->height() - area.y()), area.translated(-area.topLeft()).bottomRight()))); else CHECK(area); } void Sigmod::MapWarp::setType(const Type type) { CHECK(type); } void Sigmod::MapWarp::setToMap(const int toMap) { if (!sigmod()->mapById(toMap)) emit(error(bounds("toMap", toMap))); else CHECK(toMap); } void Sigmod::MapWarp::setToWarp(const int toWarp) { const Map* map = sigmod()->mapById(m_toMap); if (!map) emit(error(bounds("toMap", m_toMap))); else if (!map->warpById(toWarp)) emit(error(bounds("toWarp", toWarp))); else CHECK(toWarp); } void Sigmod::MapWarp::setScript(const Sigcore::Script& script) { CHECK(script); } QString Sigmod::MapWarp::name() const { return m_name; } QRect Sigmod::MapWarp::area() const { return m_area; } 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; } Sigcore::Script Sigmod::MapWarp::script() const { return m_script; } Sigmod::MapWarp& Sigmod::MapWarp::operator=(const MapWarp& rhs) { if (this == &rhs) return *this; COPY(name); COPY(area); COPY(type); COPY(toMap); COPY(toWarp); COPY(script); return *this; }