5#include "../include/TilesetParser.h"
6#include "../include/TiledJsonHelper.h"
7#include "../../system/system_utils.h"
11#define MINIZ_NO_ARCHIVE
12#include "../third_party/miniz/miniz.h"
13#include "../third_party/tinyxml2/tinyxml2.h"
29 size_t dotPos = filepath.find_last_of(
'.');
30 if (
dotPos == std::string::npos) {
31 SYSTEM_LOG <<
"TilesetParser: No file extension in " << filepath << std::endl;
35 std::string
ext = filepath.substr(
dotPos);
40 else if (
ext ==
".tsj" ||
ext ==
".json") {
44 SYSTEM_LOG <<
"TilesetParser: Unknown tileset format: " <<
ext << std::endl;
51 tinyxml2::XMLDocument
doc;
52 if (
doc.LoadFile(filepath.c_str()) != tinyxml2::XML_SUCCESS) {
53 SYSTEM_LOG <<
"TilesetParser: Failed to load TSX file: " << filepath << std::endl;
57 tinyxml2::XMLElement*
tsElement =
doc.FirstChildElement(
"tileset");
59 SYSTEM_LOG <<
"TilesetParser: No <tileset> element in " << filepath << std::endl;
80 SYSTEM_LOG <<
"TilesetParser (TSX): Parsed tileoffset ("
82 <<
") for tileset '" << tileset.
name <<
"'\n";
146 std::ifstream
file(filepath);
147 if (!
file.is_open()) {
148 SYSTEM_LOG <<
"TilesetParser: Failed to open TSJ file: " << filepath << std::endl;
158 }
catch (
const std::exception&
e) {
159 SYSTEM_LOG <<
"TilesetParser: JSON parse error in " << filepath <<
": " <<
e.what() << std::endl;
178 const auto&
offset =
j[
"tileoffset"];
181 SYSTEM_LOG <<
"TilesetParser (TSJ): Parsed tileoffset ("
183 <<
") for tileset '" << tileset.
name <<
"'\n";
199 for (
const auto&
tilePair :
j[
"tiles"].items()) {
259 if (!
j.is_array())
return;
ComponentTypeID GetComponentTypeID_Static()
void ParsePropertiesFromJSON(const nlohmann::json &j, std::map< std::string, TiledProperty > &properties)
void ParseTileFromJSON(const nlohmann::json &j, TiledTile &tile)
void ParseTileFromXML(void *element, TiledTile &tile)
bool ParseTSJ(const std::string &filepath, TiledTileset &tileset)
bool ParseTSX(const std::string &filepath, TiledTileset &tileset)
void ParsePropertiesFromXML(void *element, std::map< std::string, TiledProperty > &properties)
bool ParseFile(const std::string &filepath, TiledTileset &tileset)
std::string GetString(const json &j, const std::string &key, const std::string &defaultValue="")
int GetInt(const json &j, const std::string &key, int defaultValue=0)
bool HasKey(const json &j, const std::string &key)
bool GetBool(const json &j, const std::string &key, bool defaultValue=false)
float GetFloat(const json &j, const std::string &key, float defaultValue=0.0f)
std::string transparentcolor
std::vector< TiledTile > tiles
std::map< std::string, TiledProperty > properties