void Map::LoadMap() { pugi::xml_document xmlDoc; pugi::xml_parse_result xmlParseResult = xmlDoc.load_file(al_path_cstr(mapPath_,'/')); //should check xmlParseResult pugi::xml_node xmlMap = xmlDoc.child("map"); width_ = xmlMap.attribute("width").as_int(); height_ = xmlMap.attribute("height").as_int(); playerplaced_ = xmlMap.attribute("playerplaced").as_bool(); playerStartY_ = xmlMap.attribute("playery").as_int(); playerStartX_ = xmlMap.attribute("playerx").as_int(); //Start first node //Will probably make a node iterator later if the map has many objects in it pugi::xml_node xmlTileSet = xmlMap.child("tilevector"); int i = 0; int j = 0; tiles_.resize(0); tiles_.clear(); //is this the best way to clean those objects? tiles_.resize(width_); for(i = 0; i < tiles_.size(); i++) { tiles_[i].resize(height_); } i = 0; for (pugi::xml_node_iterator xmlCurrentTile = xmlTileSet.children().begin(); xmlCurrentTile != xmlTileSet.children().end(); xmlCurrentTile++) { Tile* currentTile = &tiles_[i][j]; for(pugi::xml_attribute_iterator xmlTileAttribute = xmlCurrentTile->attributes_begin(); xmlTileAttribute != xmlCurrentTile->attributes_end(); xmlTileAttribute++) { auto currentTileAttributeName = xmlTileAttribute->name(); if(strcmp(currentTileAttributeName,"tiletype") == 0) { currentTile->SetTileType(EnumDLL::TILETYPE(xmlTileAttribute->as_int())); } else if(strcmp(currentTileAttributeName,"x") == 0) { currentTile->SetCurrentPositionX(xmlTileAttribute->as_double()); } else if(strcmp(currentTileAttributeName,"y") == 0) { currentTile->SetCurrentPositionY(xmlTileAttribute->as_double()); } else if(strcmp(currentTileAttributeName,"clickable") == 0) { currentTile->SetClickable(xmlTileAttribute->as_bool()); } else if(strcmp(currentTileAttributeName,"color_a") == 0) { currentTile->SetColorA(xmlTileAttribute->as_float()); } else if(strcmp(currentTileAttributeName,"color_b") == 0) { currentTile->SetColorB(xmlTileAttribute->as_float()); } else if(strcmp(currentTileAttributeName,"color_g") == 0) { currentTile->SetColorG(xmlTileAttribute->as_float()); } else if(strcmp(currentTileAttributeName,"color_r") == 0) { currentTile->SetColorR(xmlTileAttribute->as_float()); } else if(strcmp(currentTileAttributeName,"height") == 0) { currentTile->SetHeight(xmlTileAttribute->as_double()); } else if(strcmp(currentTileAttributeName,"width") == 0) { currentTile->SetWidth(xmlTileAttribute->as_double()); } else if(strcmp(currentTileAttributeName,"movespeed") == 0) { currentTile->SetMoveSpeed(xmlTileAttribute->as_double()); } } //go through the tiles actual nodes for images for (pugi::xml_node_iterator xmlCurrentTileNode = xmlCurrentTile->children().begin(); xmlCurrentTileNode != xmlCurrentTile->children().end(); xmlCurrentTileNode++) { auto currentTileNodeName = xmlCurrentTileNode->name(); //if no img property it will skip from settings its property if(strcmp(currentTileNodeName,"image") == 0) { auto imgId = xmlCurrentTileNode->attribute("id").as_int(); for(int k = 0; k < imageLoader_->GetImageSetDictionary().size(); k++) { if(imageLoader_->GetImageSetDictionary()[k]->GetImageSetId() == EnumDLL::IMAGESETS::TILEIMAGESET) { for(int j = 0; j < imageLoader_->GetImageSetDictionary()[k]->GetImageDictionary().size(); j++) { if(imageLoader_->GetImageSetDictionary()[k]->GetImageDictionary()[j]->GetId() == imgId) { currentTile->SetObjectImageColor(imageLoader_->GetImageSetDictionary()[k]->GetImageDictionary()[j]); } } } } } } //if we at the end of current row of vector of tiles we go to the next vector of vectors j++; if(j % height_ == 0) { j = 0; i++; } } }