|
|
@ -1,5 +1,6 @@ |
|
|
|
#pragma once |
|
|
|
#pragma once |
|
|
|
#include "olcPixelGameEngine.h" |
|
|
|
#include "olcPixelGameEngine.h" |
|
|
|
|
|
|
|
#include "olcUTIL_Geometry2D.h" |
|
|
|
#include <strstream> |
|
|
|
#include <strstream> |
|
|
|
|
|
|
|
|
|
|
|
using namespace olc; |
|
|
|
using namespace olc; |
|
|
@ -40,6 +41,7 @@ struct Map{ |
|
|
|
std::vector<XMLTag> TilesetData; |
|
|
|
std::vector<XMLTag> TilesetData; |
|
|
|
std::vector<LayerTag> LayerData; |
|
|
|
std::vector<LayerTag> LayerData; |
|
|
|
std::vector<SpawnerTag> SpawnerData; |
|
|
|
std::vector<SpawnerTag> SpawnerData; |
|
|
|
|
|
|
|
std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData; |
|
|
|
std::string FormatLayerData(std::ostream& os, std::vector<LayerTag>tiles); |
|
|
|
std::string FormatLayerData(std::ostream& os, std::vector<LayerTag>tiles); |
|
|
|
std::string FormatSpawnerData(std::ostream& os, std::vector<SpawnerTag>tiles); |
|
|
|
std::string FormatSpawnerData(std::ostream& os, std::vector<SpawnerTag>tiles); |
|
|
|
friend std::ostream& operator << (std::ostream& os, Map& rhs); |
|
|
|
friend std::ostream& operator << (std::ostream& os, Map& rhs); |
|
|
@ -57,7 +59,6 @@ class TMXParser{ |
|
|
|
public: |
|
|
|
public: |
|
|
|
TMXParser(std::string file); |
|
|
|
TMXParser(std::string file); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef TMX_PARSER_SETUP |
|
|
|
#ifdef TMX_PARSER_SETUP |
|
|
|
#undef TMX_PARSER_SETUP |
|
|
|
#undef TMX_PARSER_SETUP |
|
|
|
const std::string XMLTag::FormatTagData(std::map<std::string,std::string>tiles){ |
|
|
|
const std::string XMLTag::FormatTagData(std::map<std::string,std::string>tiles){ |
|
|
@ -201,7 +202,7 @@ class TMXParser{ |
|
|
|
if (newTag.tag=="layer") { |
|
|
|
if (newTag.tag=="layer") { |
|
|
|
LayerTag l = {newTag}; |
|
|
|
LayerTag l = {newTag}; |
|
|
|
parsedMapInfo.LayerData.push_back(l); |
|
|
|
parsedMapInfo.LayerData.push_back(l); |
|
|
|
} else
|
|
|
|
}else
|
|
|
|
if (newTag.tag=="object"&&newTag.data["type"]=="SpawnGroup") { |
|
|
|
if (newTag.tag=="object"&&newTag.data["type"]=="SpawnGroup") { |
|
|
|
if(buildingSpawner){ |
|
|
|
if(buildingSpawner){ |
|
|
|
parsedMapInfo.SpawnerData.push_back(obj); |
|
|
|
parsedMapInfo.SpawnerData.push_back(obj); |
|
|
@ -213,6 +214,17 @@ class TMXParser{ |
|
|
|
if (newTag.tag=="object"&&newTag.data["type"]=="PlayerSpawnLocation") { |
|
|
|
if (newTag.tag=="object"&&newTag.data["type"]=="PlayerSpawnLocation") { |
|
|
|
parsedMapInfo.MapData.playerSpawnLocation={newTag.GetInteger("x")-newTag.GetInteger("width")/2,newTag.GetInteger("y")-newTag.GetInteger("height")/2}; |
|
|
|
parsedMapInfo.MapData.playerSpawnLocation={newTag.GetInteger("x")-newTag.GetInteger("width")/2,newTag.GetInteger("y")-newTag.GetInteger("height")/2}; |
|
|
|
} else
|
|
|
|
} else
|
|
|
|
|
|
|
|
if (newTag.tag=="object"&&newTag.data.find("type")!=newTag.data.end()){ |
|
|
|
|
|
|
|
//This is an object with a type that doesn't fit into other categories, we can add it to ZoneData.
|
|
|
|
|
|
|
|
if(parsedMapInfo.ZoneData.find(newTag.data["type"])!=parsedMapInfo.ZoneData.end()){ |
|
|
|
|
|
|
|
std::vector<geom2d::rect<int>>&zones=parsedMapInfo.ZoneData[newTag.data["type"]]; |
|
|
|
|
|
|
|
zones.push_back({{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
std::vector<geom2d::rect<int>>zones; |
|
|
|
|
|
|
|
zones.push_back({{newTag.GetInteger("x"),newTag.GetInteger("y")},{newTag.GetInteger("width"),newTag.GetInteger("height")}}); |
|
|
|
|
|
|
|
parsedMapInfo.ZoneData[newTag.data["type"]]=zones;
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (newTag.tag=="property"&&buildingSpawner) { |
|
|
|
if (newTag.tag=="property"&&buildingSpawner) { |
|
|
|
if(newTag.data["propertytype"]=="MonsterName"){ |
|
|
|
if(newTag.data["propertytype"]=="MonsterName"){ |
|
|
|
obj.properties.push_back(newTag); |
|
|
|
obj.properties.push_back(newTag); |
|
|
|