diff --git a/TiledCollisionEditor/TSXParser.h b/TiledCollisionEditor/TSXParser.h index b6f3d66..2e3fc36 100644 --- a/TiledCollisionEditor/TSXParser.h +++ b/TiledCollisionEditor/TSXParser.h @@ -53,12 +53,10 @@ class TSXParser{ inline Tileset&GetData(){ return parsedTilesetInfo; } - private: - class NonObject{ - public: - std::vectortags; - }; + std::vectororiginalData; + std::vectornonObjects; + private: enum NextObjectType{ OBJECT, @@ -67,8 +65,6 @@ class TSXParser{ }; Tileset parsedTilesetInfo; - std::vectororiginalData; - std::vectornonObjects; int previousTagID; std::string currentObj; NextObjectType nextObjType; @@ -137,6 +133,7 @@ class TSXParser{ if(newTag.data["name"]=="Name"){ std::string objectName=newTag.data["value"]; currentObj=objectName; + parsedTilesetInfo.objects[objectName].name=objectName; parsedTilesetInfo.objects[objectName].AddTile(parsedTilesetInfo,previousTagID); parsedTilesetInfo.objects[objectName].perspectiveObj=nextObjType==PERSPECTIVEOBJECT; } @@ -170,6 +167,11 @@ class TSXParser{ findComma=!findComma; } if(pointCount<3)ERR("WARNING! Trying to parse a shape that has less than 4 sides!"); + + for(vf2d&point:collisionQuad){ //Reposition the bounds so they are at the correct location. + point+=parsedTilesetInfo.objects[currentObj].bounds.pos; + } + parsedTilesetInfo.objects[currentObj].collisionTiles.push_back(collisionQuad); }else if (newTag.tag=="tile"){ diff --git a/TiledCollisionEditor/Tiles/Basic Tileset - Copy.tsx b/TiledCollisionEditor/Tiles/Basic Tileset - Copy - Copy - Copy - Copy - Copy.tsx similarity index 100% rename from TiledCollisionEditor/Tiles/Basic Tileset - Copy.tsx rename to TiledCollisionEditor/Tiles/Basic Tileset - Copy - Copy - Copy - Copy - Copy.tsx diff --git a/TiledCollisionEditor/Tiles/Basic Tileset.tsx b/TiledCollisionEditor/Tiles/Basic Tileset.tsx index 9fb636f..a3a34ea 100644 --- a/TiledCollisionEditor/Tiles/Basic Tileset.tsx +++ b/TiledCollisionEditor/Tiles/Basic Tileset.tsx @@ -1,824 +1,920 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TiledCollisionEditor/TilesetObject.cpp b/TiledCollisionEditor/TilesetObject.cpp index 6672e68..0cb2dae 100644 --- a/TiledCollisionEditor/TilesetObject.cpp +++ b/TiledCollisionEditor/TilesetObject.cpp @@ -75,4 +75,32 @@ void TilesetObject::AddTile(const Tileset&tileset,int tileID){ int upperLeftTileId=minTileY*tileset.columns+minTileX; this->upperLeftTileId=upperLeftTileId; } - } \ No newline at end of file + } + +std::vector>TilesetObject::OutputTag(const Tileset&activeTileset)const{ + std::vector>tileID_tileStr; + + for(int y=bounds.pos.y;y",tileID,perspectiveObj?"PerspectiveObject":"Object")+"\n"; + finalStr+="\n"; + finalStr+=std::format("",name)+"\n"; + finalStr+="\n"; + if(tileID==upperLeftTileId){ //Only the upper left tile will store the collision. + finalStr+="\n"; + for(int id=1;const Quadrilateral&quad:collisionTiles){ + finalStr+=std::format("",id)+"\n"; + finalStr+=std::format("",quad[0].x-bounds.pos.x,quad[0].y-bounds.pos.y,quad[1].x-bounds.pos.x,quad[1].y-bounds.pos.y,quad[2].x-bounds.pos.x,quad[2].y-bounds.pos.y,quad[3].x-bounds.pos.x,quad[3].y-bounds.pos.y)+"\n"; + finalStr+="\n"; + id++; + } + finalStr+="\n"; + } + finalStr+="\n"; + tileID_tileStr.push_back({tileID,finalStr}); + } + } + return tileID_tileStr; +} \ No newline at end of file diff --git a/TiledCollisionEditor/TilesetObject.h b/TiledCollisionEditor/TilesetObject.h index d7f36bf..b99a80e 100644 --- a/TiledCollisionEditor/TilesetObject.h +++ b/TiledCollisionEditor/TilesetObject.h @@ -52,4 +52,5 @@ public: geom2d::rectbounds; std::vectorcollisionTiles; void AddTile(const Tileset&tileset,int tileID); + std::vector>OutputTag(const Tileset&activeTileset)const; }; \ No newline at end of file diff --git a/TiledCollisionEditor/XMLTag.cpp b/TiledCollisionEditor/XMLTag.cpp index 288470c..573f89c 100644 --- a/TiledCollisionEditor/XMLTag.cpp +++ b/TiledCollisionEditor/XMLTag.cpp @@ -49,20 +49,20 @@ std::string XMLTag::str(){ return tag+"\n"; } -int XMLTag::GetInteger(std::string dataTag){ - return std::stoi(data[dataTag]); +int XMLTag::GetInteger(std::string dataTag)const{ + return std::stoi(data.at(dataTag)); } -float XMLTag::GetFloat(std::string dataTag){ - return std::stof(data[dataTag]); +float XMLTag::GetFloat(std::string dataTag)const{ + return std::stof(data.at(dataTag)); } -double XMLTag::GetDouble(std::string dataTag){ - return std::stod(data[dataTag]); +double XMLTag::GetDouble(std::string dataTag)const{ + return std::stod(data.at(dataTag)); } -bool XMLTag::GetBool(std::string dataTag){ - if (data[dataTag]=="0"||data[dataTag]=="false") { +bool XMLTag::GetBool(std::string dataTag)const{ + if (data.at(dataTag)=="0"||data.at(dataTag)=="false") { return false; } else { return true; @@ -73,12 +73,23 @@ std::string XMLTag::GetString(std::string dataTag){ return data[dataTag]; } -std::string XMLTag::OutputTag(std::string ending){ +std::string XMLTag::OutputTag(std::string ending)const{ std::string finalStr{"<"}; finalStr+=tag+" "; for(auto&[name,value]:data){ - finalStr+=name+"=\""+value+"\""; + finalStr+=name+"=\""+value+"\" "; } finalStr+=ending; return finalStr; +} + +std::pairNonObject::OutputTag()const{ + std::string finalStr; + finalStr+=tags[0].OutputTag()+"\n"; + finalStr+="\n"; + for(int i=1;i #include +#include struct XMLTag{ std::string tag; @@ -45,10 +46,18 @@ struct XMLTag{ const std::string FormatTagData(std::maptiles); friend std::ostream& operator << (std::ostream& os, XMLTag& rhs); std::string str(); - int GetInteger(std::string dataTag); - float GetFloat(std::string dataTag); - double GetDouble(std::string dataTag); - bool GetBool(std::string dataTag); + int GetInteger(std::string dataTag)const; + float GetFloat(std::string dataTag)const; + double GetDouble(std::string dataTag)const; + bool GetBool(std::string dataTag)const; std::string GetString(std::string dataTag); - std::string OutputTag(std::string ending=">"); + std::string OutputTag(std::string ending=">")const; +}; + + + +class NonObject{ +public: + std::vectortags; + std::pairOutputTag()const; }; \ No newline at end of file diff --git a/TiledCollisionEditor/main.cpp b/TiledCollisionEditor/main.cpp index 5e35112..9e21dcf 100644 --- a/TiledCollisionEditor/main.cpp +++ b/TiledCollisionEditor/main.cpp @@ -3,6 +3,7 @@ #include "olcPGEX_TransformedView.h" #include "olcUTIL_Camera2D.h" #include "olcPGEX_QuickGUI.h" +#include using namespace olc; using namespace olc::utils; @@ -78,12 +79,50 @@ public: } void SaveFile(){ - std::ofstream file{activeTileset}; + std::stringstream file; if(file.good()){ + const std::vectororiginalData=parsedMap.originalData; + const std::vectornonObjects=parsedMap.nonObjects; + auto xmlTag=std::find_if(originalData.begin(),originalData.end(),[](const XMLTag tag){return tag.tag=="?xml";}); + file<<""<", + activeSet.name,activeSet.tilewidth,activeSet.tileheight,(activeSet.imagewidth/activeSet.tilewidth)*(activeSet.imageheight/activeSet.tileheight),activeSet.columns)<")<", + activeSet.filename,activeSet.imagewidth,activeSet.imageheight)<>tiles; + + for(auto&[name,obj]:activeSet.objects){ + const std::vector>objTiles{obj.OutputTag(activeSet)}; + tiles.insert(tiles.end(),objTiles.begin(),objTiles.end()); + } + + for(const NonObject&obj:nonObjects){ + tiles.push_back(obj.OutputTag()); + } + + std::sort(tiles.begin(),tiles.end(),[](const std::pairtileData1,const std::pairtileData2){ + return tileData1.first"<