summaryrefslogtreecommitdiffstats
path: root/src/Data/Level.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Level.cpp')
-rw-r--r--src/Data/Level.cpp112
1 files changed, 54 insertions, 58 deletions
diff --git a/src/Data/Level.cpp b/src/Data/Level.cpp
index 6689107..283bf66 100644
--- a/src/Data/Level.cpp
+++ b/src/Data/Level.cpp
@@ -18,6 +18,9 @@
*/
#include "Level.h"
+#include "Room.h"
+#include "Gate.h"
+#include "Texture.h"
namespace ZoomEdit {
namespace Data {
@@ -32,11 +35,8 @@ Level::Level(xmlpp::Element *levelNode) : info(dynamic_cast<xmlpp::Element*>(lev
for(xmlpp::Node::NodeList::iterator room = nodeList.begin(); room != nodeList.end(); ++room) {
xmlpp::Element *roomNode = dynamic_cast<xmlpp::Element*>(*room);
- if(roomNode) {
- Room room(roomNode);
-
- rooms.insert(std::make_pair(room.getId(), room));
- }
+ if(roomNode)
+ rooms.push_back(new Room(roomNode));
}
nodeList = gatesNode->get_children("gate");
@@ -44,11 +44,8 @@ Level::Level(xmlpp::Element *levelNode) : info(dynamic_cast<xmlpp::Element*>(lev
for(xmlpp::Node::NodeList::iterator gate = nodeList.begin(); gate != nodeList.end(); ++gate) {
xmlpp::Element *gateNode = dynamic_cast<xmlpp::Element*>(*gate);
- if(gateNode) {
- Gate gate(gateNode);
-
- gates.insert(std::make_pair(gate.getId(), gate));
- }
+ if(gateNode)
+ gates.push_back(new Gate(gateNode));
}
nodeList = texturesNode->get_children("texture");
@@ -56,22 +53,23 @@ Level::Level(xmlpp::Element *levelNode) : info(dynamic_cast<xmlpp::Element*>(lev
for(xmlpp::Node::NodeList::iterator tex = nodeList.begin(); tex != nodeList.end(); ++tex) {
xmlpp::Element *texNode = dynamic_cast<xmlpp::Element*>(*tex);
- if(texNode) {
- Texture tex(texNode);
-
- textures.insert(std::make_pair(tex.getId(), tex));
- }
+ if(texNode)
+ textures.push_back(new Texture(texNode));
}
}
-Room* Level::getRoom(const Glib::ustring &id) {
- std::map<Glib::ustring,Room>::iterator room = rooms.find(id);
- return (room != rooms.end()) ? &room->second : NULL;
+Level::~Level() {
+ for(std::list<Room*>::iterator room = rooms.begin(); room != rooms.end(); ++room)
+ delete *room;
}
-const Room* Level::getRoom(const Glib::ustring &id) const {
- std::map<Glib::ustring,Room>::const_iterator room = rooms.find(id);
- return (room != rooms.end()) ? &room->second : NULL;
+Room* Level::getRoom(const Glib::ustring &id) const {
+ for(std::list<Room*>::const_iterator room = rooms.begin(); room != rooms.end(); ++room) {
+ if((*room)->getId() == id)
+ return *room;
+ }
+
+ return NULL;
}
Room* Level::addRoom(const Glib::ustring &id) {
@@ -79,26 +77,25 @@ Room* Level::addRoom(const Glib::ustring &id) {
node->set_attribute("id", id);
- return &rooms.insert(std::make_pair(id, Room(node))).first->second;
-}
-
-void Level::removeRoom(const Glib::ustring &id) {
- Room *room = getRoom(id);
- if(!room)
- return;
+ Room *room = new Room(node);
+ rooms.push_back(room);
- roomsNode->remove_child(room->getNode());
- rooms.erase(id);
+ return room;
}
-Gate* Level::getGate(const Glib::ustring &id) {
- std::map<Glib::ustring,Gate>::iterator gate = gates.find(id);
- return (gate != gates.end()) ? &gate->second : NULL;
+void Level::removeRoom(Room *room) {
+ roomsNode->remove_child(room->getNode());
+ rooms.remove(room);
+ delete room;
}
-const Gate* Level::getGate(const Glib::ustring &id) const {
- std::map<Glib::ustring,Gate>::const_iterator gate = gates.find(id);
- return (gate != gates.end()) ? &gate->second : NULL;
+Gate* Level::getGate(const Glib::ustring &id) const {
+ for(std::list<Gate*>::const_iterator gate = gates.begin(); gate != gates.end(); ++gate) {
+ if((*gate)->getId() == id)
+ return *gate;
+ }
+
+ return NULL;
}
Gate* Level::addGate(const Glib::ustring &id) {
@@ -108,26 +105,25 @@ Gate* Level::addGate(const Glib::ustring &id) {
node->set_attribute("room1", "");
node->set_attribute("room2", "");
- return &gates.insert(std::make_pair(id, Gate(node))).first->second;
-}
-
-void Level::removeGate(const Glib::ustring &id) {
- Gate *gate = getGate(id);
- if(!gate)
- return;
+ Gate *gate = new Gate(node);
+ gates.push_back(gate);
- gatesNode->remove_child(gate->getNode());
- gates.erase(id);
+ return gate;
}
-Texture* Level::getTexture(const Glib::ustring &id) {
- std::map<Glib::ustring,Texture>::iterator tex = textures.find(id);
- return (tex != textures.end()) ? &tex->second : NULL;
+void Level::removeGate(Gate *gate) {
+ gatesNode->remove_child(gate->getNode());
+ gates.remove(gate);
+ delete gate;
}
-const Texture* Level::getTexture(const Glib::ustring &id) const {
- std::map<Glib::ustring,Texture>::const_iterator tex = textures.find(id);
- return (tex != textures.end()) ? &tex->second : NULL;
+Texture* Level::getTexture(const Glib::ustring &id) const {
+ for(std::list<Texture*>::const_iterator tex = textures.begin(); tex != textures.end(); ++tex) {
+ if((*tex)->getId() == id)
+ return *tex;
+ }
+
+ return NULL;
}
Texture* Level::addTexture(const Glib::ustring &id) {
@@ -136,16 +132,16 @@ Texture* Level::addTexture(const Glib::ustring &id) {
node->set_attribute("id", id);
node->set_attribute("name", "");
- return &textures.insert(std::make_pair(id, Texture(node))).first->second;
+ Texture *tex = new Texture(node);
+ textures.push_back(tex);
+
+ return tex;
}
-void Level::removeTexture(const Glib::ustring &id) {
- Texture *tex = getTexture(id);
- if(!tex)
- return;
-
+void Level::removeTexture(Texture *tex) {
texturesNode->remove_child(tex->getNode());
- textures.erase(id);
+ textures.remove(tex);
+ delete tex;
}
}