#pragma once #include "olcPixelGameEngine.h" #include #include "TMXParser.h" #include "Map.h" #include "olcUTIL_Geometry2D.h" using namespace olc; struct Tileset{ XMLTag ImageData; std::map ForegroundTileData; std::map UpperForegroundTileData; std::map CollisionData; std::map StaircaseData; friend std::ostream& operator << (std::ostream& os, Tileset& rhs); }; class TSXParser{ public: Tileset GetData(); private: Tileset parsedTilesetInfo; void ParseTag(std::string tag); std::string previousTag; int previousTagID; std::string staircaseTag=""; public: TSXParser(std::string file); }; #ifdef TSX_PARSER_SETUP #undef TSX_PARSER_SETUP Tileset TSXParser::GetData() { return parsedTilesetInfo; } std::ostream&operator<<(std::ostream& os, Tileset& rhs){ os<0){ if (newTag.tag.length()==0) { //Tag's empty, so first line is the tag. newTag.tag=data; std::cout<<"Tag: "<{{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}; parsedTilesetInfo.CollisionData[previousTagID]=data; } std::cout<<"\n"<<"=============\n"; } TSXParser::TSXParser(std::string file){ std::ifstream f(file,std::ios::in); std::string accumulator=""; while (f.good()) { std::string data; f>>data; if (data.empty()) continue; if (accumulator.length()>0) { accumulator+=" "+data; //Check if it ends with '>' if (data[data.length()-1]=='>') { ParseTag(accumulator); accumulator=""; } } else if (data[0]=='<') { //Beginning of XML tag. accumulator=data; if(accumulator.length()>1&&accumulator.at(1)=='/'){ accumulator=""; //Restart because this is an end tag. } if(accumulator.length()>1&&accumulator.find('>')!=std::string::npos){ accumulator=""; //Restart because this tag has nothing in it! } } } std::cout<<"Parsed Tileset Data:\n"<