|
|
|
@ -3,6 +3,7 @@ |
|
|
|
|
#include "olcPGEX_TransformedView.h" |
|
|
|
|
#include "olcUTIL_Camera2D.h" |
|
|
|
|
#include "olcPGEX_QuickGUI.h" |
|
|
|
|
#include <variant> |
|
|
|
|
|
|
|
|
|
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::vector<XMLTag>originalData=parsedMap.originalData; |
|
|
|
|
const std::vector<NonObject>nonObjects=parsedMap.nonObjects; |
|
|
|
|
auto xmlTag=std::find_if(originalData.begin(),originalData.end(),[](const XMLTag tag){return tag.tag=="?xml";}); |
|
|
|
|
file<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<std::endl; |
|
|
|
|
|
|
|
|
|
const Tileset&activeSet=tilesets.at(activeTileset); |
|
|
|
|
file<<std::format("<tileset name=\"{}\" tilewidth=\"{}\" tileheight=\"{}\" tilecount=\"{}\" columns=\"{}\">", |
|
|
|
|
activeSet.name,activeSet.tilewidth,activeSet.tileheight,(activeSet.imagewidth/activeSet.tilewidth)*(activeSet.imageheight/activeSet.tileheight),activeSet.columns)<<std::endl; |
|
|
|
|
|
|
|
|
|
auto transformationsTag=std::find_if(originalData.begin(),originalData.end(),[](const XMLTag tag){return tag.tag=="transformations";}); |
|
|
|
|
file<<(*transformationsTag).OutputTag("/>")<<std::endl; |
|
|
|
|
|
|
|
|
|
file<<std::format("<image source=\"{}\" width=\"{}\" height=\"{}\"/>", |
|
|
|
|
activeSet.filename,activeSet.imagewidth,activeSet.imageheight)<<std::endl; |
|
|
|
|
|
|
|
|
|
std::vector<std::pair<int,std::string>>tiles; |
|
|
|
|
|
|
|
|
|
for(auto&[name,obj]:activeSet.objects){ |
|
|
|
|
const std::vector<std::pair<int,std::string>>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::pair<int,std::string>tileData1,const std::pair<int,std::string>tileData2){ |
|
|
|
|
return tileData1.first<tileData2.first; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
for(auto&[tileID,str]:tiles){ |
|
|
|
|
file<<str<<std::endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
file<<"</tileset>"<<std::endl; |
|
|
|
|
}else{ |
|
|
|
|
std::cout<<"WARNING! File not available for saving! Failed to save!"<<std::endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::ofstream saveFile{activeTileset}; |
|
|
|
|
saveFile<<file.str()<<std::endl; |
|
|
|
|
saveFile.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Update(){ |
|
|
|
@ -186,6 +225,10 @@ public: |
|
|
|
|
if(GetMouse(Mouse::RIGHT).bPressed&&!EditingQuad&&!dragTranslate){ |
|
|
|
|
if(highlightedQuad!=nullptr){ |
|
|
|
|
std::erase_if(tilesets[activeTileset].objects[selectedObj].collisionTiles,[&](Quadrilateral&q){return &q==highlightedQuad;}); |
|
|
|
|
editingPoint=4; |
|
|
|
|
dragging=false; |
|
|
|
|
editingQuad=nullptr; |
|
|
|
|
dragTranslate=false; |
|
|
|
|
SaveFile(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|