diff options
Diffstat (limited to 'frontend/load_dungeon.cpp')
-rw-r--r-- | frontend/load_dungeon.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/frontend/load_dungeon.cpp b/frontend/load_dungeon.cpp index ff68109..41c7fc4 100644 --- a/frontend/load_dungeon.cpp +++ b/frontend/load_dungeon.cpp @@ -10,6 +10,8 @@ #include "load_dungeon.h" #include "Exception.h" +#include "GameData.h" +#include "backend/Object.h" #include "strings.h" using namespace std; @@ -37,28 +39,46 @@ unique_ptr<Dungeon> load_dungeon(const string & filename) { if (!locations) throw Exception("XML-bestand mist een <locaties> tag"); - LocationFactory factory; + GameData & gamedata = GameData::get_instance(); + struct TempData { Location * location; unsigned edges[4]; }; map<unsigned, TempData> temp_map; + for (xml_node & tag : locations) { const char * name = tag.text().as_string(); const char * description = tag.child("beschrijving").text().as_string(); - // vector<string> objects_hidden = split_string(tag.attribute("objectenverborgen").as_string(), ";"); - // vector<string> objects_visible = split_string(tag.attribute("objectenzichtbaar").as_string(), ";"); - // vector<string> enemies = split_string(tag.attribute("vijand").as_string(), ";"); + Location * location = LocationFactory::create_location(name, description); - Location * location = factory.create_location(name, description); + vector<string> objects_hidden = str_split(tag.attribute("objectenverborgen").as_string(), ";"); + for (string & name : objects_hidden) { + Object * object = gamedata.create_object(name); + object->set_hidden(true); + location->add_object(object); + } + vector<string> objects_visible = str_split(tag.attribute("objectenzichtbaar").as_string(), ";"); + for (string & name : objects_visible) { + Object * object = gamedata.create_object(name); + object->set_hidden(false); + location->add_object(object); + } + + vector<string> enemies = str_split(tag.attribute("vijand").as_string(), ";"); + for (string & name : enemies) { + Enemy * enemy = gamedata.create_enemy(name); + location->add_enemy(enemy); + } + temp_map[tag.attribute("id").as_uint()] = { .location = location, .edges = { [Direction::NORTH] = tag.attribute("noord").as_uint(0), - [Direction::EAST] = tag.attribute("oost").as_uint(0), + [Direction::EAST] = tag.attribute("oost").as_uint(0), [Direction::SOUTH] = tag.attribute("zuid").as_uint(0), - [Direction::WEST] = tag.attribute("west").as_uint(0), + [Direction::WEST] = tag.attribute("west").as_uint(0), }, }; dungeon->add_location(location); |