diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index a757e859..e83e13df 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -7,6 +7,7 @@ #include "Class.h" #include "Version.h" #include "TMXParser.h" +#include "TSXParser.h" #include "DEFINES.h" //192x192 @@ -770,6 +771,7 @@ void Crawler::RenderHud(){ DrawStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4 - vf2d{ 0.4,0 }, versionStr, WHITE, { 0.4,0.4 }); DrawStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4 - vf2d{ 0,0.4 }, versionStr, WHITE, { 0.4,0.4 }); DrawStringDecal(vf2d{ GetScreenSize() } - vf2d{ GetTextSize(versionStr) }*0.4, versionStr, BLACK,{0.4,0.4}); + DrawDecal({0,0},MAP_TILESETS["assets/maps/"+MAP_DATA[LEVEL1].TilesetData[1].data["source"]]->Decal()); } void Crawler::AddEffect(Effect foreground,Effect background){ @@ -802,12 +804,10 @@ void Crawler::InitializeLevel(std::string mapFile,MapName map){ std::string baseDir=mapFile.substr(0,slashMarker+1); MAP_DATA[map]=level.GetData(); for(XMLTag&tag:MAP_DATA[map].TilesetData){ - if(tag.tag=="tileset"&&MAP_TILESETS.find(tag.data["source"])==MAP_TILESETS.end()){ - Renderable*r=new Renderable(); - MAP_TILESETS[tag.data["source"]]=r; - r->Load(baseDir+tag.data["source"]); - std::cout<<"Missing tileset:"<Load("assets/maps/"+tileset.GetData().ImageData.data["source"]); } } diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index ee718fef..d1946e90 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -183,6 +183,7 @@ + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index 517f8c84..e1f8416d 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -84,6 +84,9 @@ Header Files + + Header Files + diff --git a/Crawler/TSXParser.h b/Crawler/TSXParser.h new file mode 100644 index 00000000..2c16ec5b --- /dev/null +++ b/Crawler/TSXParser.h @@ -0,0 +1,116 @@ +#pragma once +#include "olcPixelGameEngine.h" +#include +#include "TMXParser.h" + +using namespace olc; + +struct Tileset{ + XMLTag ImageData; + friend std::ostream& operator << (std::ostream& os, Tileset& rhs); +}; + +class TSXParser{ + public: + Tileset GetData(); + private: + Tileset parsedTilesetInfo; + void ParseTag(std::string tag); + 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: "<>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"<