Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
TiledLevelLoader.h
Go to the documentation of this file.
1/*
2 * TiledLevelLoader.h - Main loader for Tiled MapEditor files
3 *
4 * Loads and parses Tiled .tmj (JSON map) files with full support for:
5 * - Orthogonal and isometric orientations
6 * - Finite and infinite (chunked) maps
7 * - All layer types (tile, object, image, group)
8 * - External tilesets (.tsx, .tsj)
9 * - Embedded tilesets
10 * - Custom properties
11 * - Parallax scrolling
12 */
13
14#pragma once
15
16#include "TiledStructures.h"
17#include "TiledJsonHelper.h"
18#include <string>
19#include <memory>
20
21namespace Olympe {
22namespace Tiled {
23
25 {
26 public:
29
30 // Load map from .tmj (JSON) or .tmx (XML) file (auto-detect by extension)
31 bool LoadFromFile(const std::string& filepath, TiledMap& outMap);
32
33 // Get last error message
34 const std::string& GetLastError() const { return lastError_; }
35
36 private:
37 // Parse map JSON
38 bool ParseMap(const json& j, TiledMap& map);
39
40 // Parse map XML (TMX format)
41 bool ParseMapXML(void* doc, TiledMap& map);
42
43 // Parse layers
44 bool ParseLayer(const json& j, std::shared_ptr<TiledLayer>& layer);
45 bool ParseLayerXML(void* element, std::shared_ptr<TiledLayer>& layer);
46
47 bool ParseTileLayer(const json& j, TiledLayer& layer);
48 bool ParseTileLayerXML(void* element, TiledLayer& layer);
49
50 bool ParseObjectLayer(const json& j, TiledLayer& layer);
51 bool ParseObjectLayerXML(void* element, TiledLayer& layer);
52
53 bool ParseImageLayer(const json& j, TiledLayer& layer);
54 bool ParseImageLayerXML(void* element, TiledLayer& layer);
55
56 bool ParseGroupLayer(const json& j, TiledLayer& layer);
57 bool ParseGroupLayerXML(void* element, TiledLayer& layer);
58
59 // Parse objects
60 bool ParseObject(const json& j, TiledObject& object);
61 bool ParseObjectXML(void* element, TiledObject& object);
62
63 // Parse tilesets
64 bool ParseTileset(const json& j, TiledTileset& tileset, const std::string& mapDir);
65 bool ParseTilesetXML(void* element, TiledTileset& tileset, const std::string& mapDir);
66 bool LoadExternalTileset(const std::string& filepath, TiledTileset& tileset);
67
68 // Parse chunks (for infinite maps)
69 bool ParseChunk(const json& j, TiledChunk& chunk,
70 const std::string& layerEncoding,
71 const std::string& layerCompression);
73 const std::string& layerEncoding,
74 const std::string& layerCompression);
75
76 // Parse properties
77 void ParseProperties(const json& j, std::map<std::string, TiledProperty>& properties);
78 void ParsePropertiesXML(void* element, std::map<std::string, TiledProperty>& properties);
79 void ParseProperty(const json& j, TiledProperty& prop);
81
82 // Parse tile data
83 bool ParseTileData(const json& j, TiledLayer& layer);
84 bool ParseTileDataXML(void* element, TiledLayer& layer);
85
86 // Helper: resolve relative path from map directory
87 std::string ResolvePath(const std::string& mapDir, const std::string& relativePath);
88
89 // Helper: get directory from file path
90 std::string GetDirectory(const std::string& filepath);
91
92 // Helper: read file to string
93 bool ReadFile(const std::string& filepath, std::string& outContent);
94
95 std::string lastError_;
96 };
97
98} // namespace Tiled
99} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
bool ReadFile(const std::string &filepath, std::string &outContent)
bool ParseMapXML(void *doc, TiledMap &map)
bool ParseImageLayer(const json &j, TiledLayer &layer)
bool ParseTilesetXML(void *element, TiledTileset &tileset, const std::string &mapDir)
bool ParseTileLayerXML(void *element, TiledLayer &layer)
bool LoadExternalTileset(const std::string &filepath, TiledTileset &tileset)
bool ParseTileData(const json &j, TiledLayer &layer)
void ParseProperties(const json &j, std::map< std::string, TiledProperty > &properties)
bool ParseMap(const json &j, TiledMap &map)
bool ParseObject(const json &j, TiledObject &object)
bool ParseLayer(const json &j, std::shared_ptr< TiledLayer > &layer)
const std::string & GetLastError() const
bool ParseObjectLayerXML(void *element, TiledLayer &layer)
bool ParseImageLayerXML(void *element, TiledLayer &layer)
void ParsePropertiesXML(void *element, std::map< std::string, TiledProperty > &properties)
bool ParseChunk(const json &j, TiledChunk &chunk, const std::string &layerEncoding, const std::string &layerCompression)
bool ParseTileset(const json &j, TiledTileset &tileset, const std::string &mapDir)
void ParseProperty(const json &j, TiledProperty &prop)
bool ParseChunkXML(void *element, TiledChunk &chunk, const std::string &layerEncoding, const std::string &layerCompression)
std::string GetDirectory(const std::string &filepath)
std::string ResolvePath(const std::string &mapDir, const std::string &relativePath)
bool ParseTileLayer(const json &j, TiledLayer &layer)
bool ParseObjectXML(void *element, TiledObject &object)
void ParsePropertyXML(void *element, TiledProperty &prop)
bool ParseLayerXML(void *element, std::shared_ptr< TiledLayer > &layer)
bool ParseObjectLayer(const json &j, TiledLayer &layer)
bool LoadFromFile(const std::string &filepath, TiledMap &outMap)
bool ParseGroupLayer(const json &j, TiledLayer &layer)
bool ParseGroupLayerXML(void *element, TiledLayer &layer)
bool ParseTileDataXML(void *element, TiledLayer &layer)
nlohmann::json json