From 1d3b07eb98bfae29b7af5b83da7c20b4c3a2beed Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 21 Jun 2023 14:30:14 -0700 Subject: [PATCH] Revamped TMXParser.h such that there is a separation between function declarations and definitions for modular support. --- Crawler/Crawler.h | 4 + Crawler/Crawler.vcxproj | 1 + Crawler/Crawler.vcxproj.filters | 3 + Crawler/Map.h | 5 + Crawler/TMXParser.h | 175 +++++++++++++++++--------------- Crawler/Version.h | 2 +- Crawler/pixelGameEngine.cpp | 4 +- 7 files changed, 111 insertions(+), 83 deletions(-) create mode 100644 Crawler/Map.h diff --git a/Crawler/Crawler.h b/Crawler/Crawler.h index 5be77c89..a09ce89e 100644 --- a/Crawler/Crawler.h +++ b/Crawler/Crawler.h @@ -7,6 +7,9 @@ #include "Player.h" #include "olcUTIL_Camera2D.h" #include "Effect.h" +#include "Map.h" +#include "TMXParser.h" + class Crawler : public olc::PixelGameEngine { @@ -17,6 +20,7 @@ class Crawler : public olc::PixelGameEngine GFX_Heart,GFX_BLOCK_BUBBLE,GFX_Ranger_Sheet,GFX_Wizard_Sheet, GFX_Battlecry_Effect,GFX_Mana,GFX_SonicSlash; std::vectorforegroundEffects,backgroundEffects; + std::mapMAP_DATA; vf2d worldShake={}; float worldShakeTime=0; float lastWorldShakeAdjust=0; diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index 364e6471..ee718fef 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -171,6 +171,7 @@ + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index 067fd35e..517f8c84 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -81,6 +81,9 @@ Header Files + + Header Files + diff --git a/Crawler/Map.h b/Crawler/Map.h new file mode 100644 index 00000000..854317b1 --- /dev/null +++ b/Crawler/Map.h @@ -0,0 +1,5 @@ +#pragma once +enum MapName{ + LEVEL1, + LEVEL2, +}; \ No newline at end of file diff --git a/Crawler/TMXParser.h b/Crawler/TMXParser.h index 96dad3dc..e07efc6a 100644 --- a/Crawler/TMXParser.h +++ b/Crawler/TMXParser.h @@ -7,106 +7,121 @@ using namespace olc; struct XMLTag{ std::string tag; std::map data; - const std::string FormatTagData(std::maptiles) { + const std::string FormatTagData(std::maptiles); + friend std::ostream& operator << (std::ostream& os, XMLTag& rhs); + int GetInteger(std::string dataTag); + double GetDouble(std::string dataTag); + bool GetBool(std::string dataTag); +}; + +struct LayerTag{ + XMLTag tag; + std::vector> tiles; + std::string str(); +}; + +struct SpawnerTag{ + XMLTag ObjectData; + std::vectorproperties; + std::string str(); + friend std::ostream& operator << (std::ostream& os, SpawnerTag& rhs); +}; + +struct Map{ + XMLTag MapData; + XMLTag TilesetData; + std::vector LayerData; + std::vector SpawnerData; + std::string FormatLayerData(std::ostream& os, std::vectortiles); + std::string FormatSpawnerData(std::ostream& os, std::vectortiles); + friend std::ostream& operator << (std::ostream& os, Map& rhs); +}; + +class TMXParser{ + public: + Map GetData(); + private: + Map parsedMapInfo; + bool buildingSpawner=false; + SpawnerTag obj; + void ParseTag(std::string tag); + public: + TMXParser(std::string file); +}; + +#ifdef TMX_PARSER_SETUP +#undef TMX_PARSER_SETUP + const std::string XMLTag::FormatTagData(std::maptiles){ std::string displayStr=""; for (std::map::iterator it=data.begin();it!=data.end();it++) { displayStr+=" "+it->first+": "+it->second+"\n"; } return displayStr; } - friend std::ostream& operator << (std::ostream& os, XMLTag& rhs) { + std::ostream& operator << (std::ostream& os, XMLTag& rhs){ os << rhs.tag <<"\n"<< rhs.FormatTagData(rhs.data) <<"\n"; - return os; } - - int GetInteger(std::string dataTag) { + return os; + } + int XMLTag::GetInteger(std::string dataTag) { return std::stoi(data[dataTag]); } - double GetDouble(std::string dataTag) { + double XMLTag::GetDouble(std::string dataTag) { return std::stod(data[dataTag]); } - bool GetBool(std::string dataTag) { + bool XMLTag::GetBool(std::string dataTag) { if (data[dataTag]=="0") { return false; } else { return true; } - } -}; -struct LayerTag{ - XMLTag tag; - std::vector> tiles; - std::string str() { + std::string LayerTag::str() { std::string displayStr=tag.tag+"\n"+tag.FormatTagData(tag.data); displayStr+=" DATA ("+std::to_string(tiles[0].size())+"x"+std::to_string(tiles.size())+")\n"; return displayStr; } -}; - -struct SpawnerTag{ - XMLTag ObjectData; - std::vectorproperties; - std::string str() { + std::string SpawnerTag::str() { std::string displayStr=ObjectData.tag+"\n"+ObjectData.FormatTagData(ObjectData.data); for(XMLTag tag:properties){ displayStr+=" ("+tag.FormatTagData(tag.data)+")\n"; } return displayStr; } - friend std::ostream& operator << (std::ostream& os, SpawnerTag& rhs) { + std::ostream& operator << (std::ostream& os, SpawnerTag& rhs) { os << rhs.str()<<"\n"; - - return os; } -}; - -struct Map{ - XMLTag MapData; - XMLTag TilesetData; - std::vector LayerData; - std::vector SpawnerData; - std::string FormatLayerData(std::ostream& os, std::vectortiles) { + return os; + } + std::string Map::FormatLayerData(std::ostream& os, std::vectortiles) { std::string displayStr; for (int i=0;itiles) { + std::string Map::FormatSpawnerData(std::ostream& os, std::vectortiles) { std::string displayStr; for (int i=0;i