generated from sigonasr2/CPlusPlusProjectTemplate
TMX Parser value conversions
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
3932709e2c
commit
acbac940b0
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.8" tiledversion="1.8.5" orientation="orthogonal" renderorder="right-down" width="384" height="192" tilewidth="16" tileheight="16" infinite="0" nextlayerid="9" nextobjectid="1">
|
||||
<map version="1.8" tiledversion="1.8.5" orientation="orthogonal" renderorder="right-down" width="384" height="192" tilewidth="16" tileheight="16" infinite="1" nextlayerid="9" nextobjectid="1">
|
||||
<tileset firstgid="1" source="../gfx/tilesets/tilesheet_terra.tsx"/>
|
||||
<layer id="1" name="1_Oceans_Terrain" width="384" height="192">
|
||||
<data encoding="csv">
|
||||
|
Binary file not shown.
31
TMXParser.h
31
TMXParser.h
@ -20,6 +20,21 @@ struct XMLTag{
|
||||
rhs.FormatTagData(rhs.data) <<"\n";
|
||||
|
||||
return os; }
|
||||
|
||||
int GetInteger(std::string dataTag) {
|
||||
return std::stoi(data[dataTag]);
|
||||
}
|
||||
double GetDouble(std::string dataTag) {
|
||||
return std::stod(data[dataTag]);
|
||||
}
|
||||
bool GetBool(std::string dataTag) {
|
||||
if (data[dataTag]=="0") {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
struct LayerTag{
|
||||
@ -53,6 +68,13 @@ struct Map{
|
||||
};
|
||||
|
||||
class TMXParser{
|
||||
|
||||
public:
|
||||
|
||||
Map GetData() {
|
||||
return parsedMapInfo;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Map parsedMapInfo;
|
||||
@ -71,6 +93,11 @@ class TMXParser{
|
||||
} else {
|
||||
std::string key = data.substr(0,data.find("="));
|
||||
std::string value = data.substr(data.find("=")+1,std::string::npos);
|
||||
|
||||
//Strip Quotation marks.
|
||||
value = value.substr(1,std::string::npos);
|
||||
value = value.substr(0,value.length()-1);
|
||||
|
||||
newTag.data[key]=value;
|
||||
std::cout<<" "<<key<<":"<<newTag.data[key]<<"\n";
|
||||
}
|
||||
@ -92,8 +119,8 @@ class TMXParser{
|
||||
}
|
||||
|
||||
public:
|
||||
TMXParser(){
|
||||
std::ifstream f("00_test_room.tmx",std::ios::in);
|
||||
TMXParser(std::string file){
|
||||
std::ifstream f(file,std::ios::in);
|
||||
|
||||
std::string accumulator="";
|
||||
|
||||
|
10
main.cpp
10
main.cpp
@ -6,6 +6,14 @@
|
||||
using namespace olc;
|
||||
|
||||
int main(){
|
||||
TMXParser parser;
|
||||
TMXParser parser("00_test_room.tmx");
|
||||
Map mData = parser.GetData();
|
||||
XMLTag mapTag = mData.MapData;
|
||||
double version = mapTag.GetDouble("version");
|
||||
int width = mapTag.GetInteger("width");
|
||||
int height = mapTag.GetInteger("height");
|
||||
bool isInfinite = mapTag.GetBool("infinite");
|
||||
std::cout<<version<<": "<<width<<","<<height<<","<<isInfinite;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user