### Get Array Field (ArrayPoint Example) Source: https://github.com/madour/ldtkloader/wiki/FieldsContainer Retrieves an array field of type ArrayPoint by its name. Iterates through the array, checking each element for null before accessing its value. ```c++ const auto& array_field = level.getField("spawns"); // iterate on the array field for (const auto& field : array_field) { if (!field.is_null()) { // get the field value const auto& point = field.value(); } } ``` -------------------------------- ### Get Single Value Field (Color Example) Source: https://github.com/madour/ldtkloader/wiki/FieldsContainer Retrieves a single value field of type Color by its name. Checks if the field is null before accessing its value. ```c++ const auto& field = entity.getField("hair_color"); if (!field.is_null()) { // get the field value const auto& hair_color = field.value(); } ``` -------------------------------- ### Get Background Color Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves the default background color of the LDtk project. ```c++ ldtk::Project::getBgColor() const -> const ldtk::Color& ``` -------------------------------- ### Get Layer Tileset Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the tileset used by the layer. Throws an exception if no tileset is present. ```c++ ldtk::Layer::getTileset() const -> const ldtk::Tileset& ``` -------------------------------- ### Get Layer Name Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the name of the layer as a string. ```c++ ldtk::Layer::getName() const -> const std::string& ``` -------------------------------- ### Get Entities by Tag Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves a vector of reference wrappers for entities associated with the given tag name. Similar to getting entities by name, explicit type specification is required during iteration due to reference wrappers. ```c++ ldtk::Layer::getEntitiesByTag(const std::string& tag) const -> const std::vector>& ``` ```c++ for (const ldtk::Entity& actionable : layer.getEntitiesByTag("actionable")) { // ... } ``` -------------------------------- ### CMake Project Setup and Dependencies Source: https://github.com/madour/ldtkloader/blob/master/examples/SDL/CMakeLists.txt Configures the CMake version, project name, module path, and finds required SDL2 and SDL2_image libraries. This is essential for building SDL-based applications. ```cmake cmake_minimum_required(VERSION 3.10) if (POLICY CMP0074) cmake_policy(SET CMP0074 NEW) endif() project(LDtkLoader-SDL) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH}) # find SDL2 and SDL2_image find_package(SDL2 REQUIRED) find_package(SDL2_image REQUIRED) ``` -------------------------------- ### ldtk::Layer::allTiles Source: https://github.com/madour/ldtkloader/wiki/Layer Gets all tiles within the Layer. ```APIDOC ## ldtk::Layer::allTiles ### Description Returns a vector containing all the [[Tile|Tile#class--ldtkTile]]s in the Layer, ordered correctly. ### Method const std::vector& allTiles() const ### Returns A vector of all tiles in the layer. ``` -------------------------------- ### Use LDtkLoader in a CMake Project Source: https://github.com/madour/ldtkloader/blob/master/README.md Shows how to integrate the LDtkLoader library into your CMake project after installation. Includes commands for finding the package and linking the library. ```cmake find_package(LDtkLoader 1.5) target_link_libraries(YourTarget PRIVATE LDtkLoader::LDtkLoader) ``` -------------------------------- ### Get All Tiles Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves a vector containing all tiles within the layer, in their correct order. ```c++ ldtk::Layer::allTiles() const -> const std::vector& ``` -------------------------------- ### ldtk::Layer::getIntGridValPositions Source: https://github.com/madour/ldtkloader/wiki/Layer Gets all positions of a specific IntGrid value. ```APIDOC ## ldtk::Layer::getIntGridValPositions ### Description Returns a vector of all positions where a specific [[IntGridValue|DataTypes#struct--ldtkIntGridValue]] is located. ### Method std::vector getIntGridValPositions(const IntGridValue& val) const ### Parameters #### Path Parameters - **val** (const IntGridValue&) - The IntGrid value to find positions for. ### Returns A vector of `ldtk::IntPoint` representing the positions of the specified IntGrid value. ``` -------------------------------- ### Get Entity Name Source: https://github.com/madour/ldtkloader/wiki/Entity Retrieves the name of the entity. Use this to identify the type of entity. ```c++ ldtk::Entity::getName() const -> const std::string& ``` -------------------------------- ### Get All Tags (Inherited) Source: https://github.com/madour/ldtkloader/wiki/Tileset Inherited from TagsContainer. Returns a vector of all tags present in the tileset. ```c++ ldtk::Tileset::allTags() const -> const std::vector& ``` -------------------------------- ### Get Layer Opacity Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the opacity of the layer, a float value between 0.0 and 1.0. ```c++ ldtk::Layer::getOpacity() const -> float ``` -------------------------------- ### Get Tile at Position Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the tile at a specific grid coordinate (x, y). Returns a 'None' tile if no tile exists at the position. ```c++ ldtk::Layer::getTile(int x, int y) const -> const Tile& ``` -------------------------------- ### Get Entity Definition by Name Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves an EntityDef by its string name. Throws an exception if no matching EntityDef is found. ```c++ ldtk::Project::getEntityDef(const std::string& name) const -> const ldtk::EntityDef& ``` -------------------------------- ### Get Tileset by Name Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves a specific Tileset from the project using its string name. Throws an invalid_argument exception if no Tileset with the given name is found. ```c++ ldtk::Project::getTileset(const std::string& name) const -> const ldtk::Tileset& ``` -------------------------------- ### Get All Tilesets Source: https://github.com/madour/ldtkloader/wiki/Project Returns a vector containing all the Tilesets defined within the LDtk project. Each element is a reference to a ldtk::Tileset object. ```c++ ldtk::Project::allTilesets() const -> const std::vector& ``` -------------------------------- ### Get Entity Size Source: https://github.com/madour/ldtkloader/wiki/Entity Retrieves the size of the entity in pixels. This is useful for collision detection or rendering. ```c++ ldtk::Entity::getSize() const -> const ldtk::IntPoint& ``` -------------------------------- ### Get Tileset by ID Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves a specific Tileset from the project using its integer ID. Throws an invalid_argument exception if no Tileset with the given ID is found. ```c++ ldtk::Project::getTileset(int id) const -> const ldtk::Tileset& ``` -------------------------------- ### Get All Table of Contents Entities Source: https://github.com/madour/ldtkloader/wiki/Project Returns a vector of all EntityRefs located in the Table of Contents (ToC). ```c++ ldtk::Project::allTocEntities() const -> const std::vector& ``` -------------------------------- ### Get Layer Type Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the type of the layer, which can be IntGrid, Entities, Tiles, or AutoLayer. ```c++ ldtk::Layer::getType() const -> const ldtk::LayerType& ``` -------------------------------- ### Get Entity Color Source: https://github.com/madour/ldtkloader/wiki/Entity Retrieves the color associated with the entity. This can be used for visual representation or effects. ```c++ ldtk::Entity::getColor() const -> const ldtk::Color& ``` -------------------------------- ### Get World Background Color Source: https://github.com/madour/ldtkloader/wiki/World Retrieves the default background color of the World. The color is returned as an ldtk::Color object. ```c++ ldtk::World::getBgColor() const -> const ldtk::Color& ``` -------------------------------- ### Get Tiles by Enum Tag Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves tiles tagged with a specific enum value. Requires explicit type specification when iterating over the results. ```c++ ldtk::Layer::getTilesByEnumTag(const EnumValue&) const -> const std::vector>& ``` ```c++ const auto& chest_enumval = world.getEnum("Items")["Chest"]; for (const ldtk::Tile& chest_tiles : layer.getTilesByEnumTag(chest_enumval)) { // ... } ``` -------------------------------- ### Get Single World (for single-world projects) Source: https://github.com/madour/ldtkloader/wiki/Project For LDtk projects containing only one world, this method returns that World object. If the project has multiple worlds, an invalid_argument exception is thrown. ```c++ ldtk::Project::getWorld() const -> const ldtk::Project& ``` -------------------------------- ### Get All World Tilesets Source: https://github.com/madour/ldtkloader/wiki/World Retrieves a vector containing all the tilesets associated with the World. Each element in the vector is an ldtk::Tileset object. ```c++ ldtk::World::allTilesets() const -> const std::vector& ``` -------------------------------- ### Get Entity Grid Position Source: https://github.com/madour/ldtkloader/wiki/Entity Retrieves the position of the entity in grid coordinates. This is useful for tile-based logic. ```c++ ldtk::Entity::getGridPosition() const -> const ldtk::IntPoint& ``` -------------------------------- ### Get World Tileset by ID or Name Source: https://github.com/madour/ldtkloader/wiki/World Retrieves a specific tileset from the World using its ID or name. Throws an invalid_argument exception if no matching tileset is found. ```c++ ldtk::World::getTileset(int id) const -> const ldtk::Tileset& ``` ```c++ ldtk::World::getTileset(const std::string& name) const -> const ldtk::Tileset& ``` -------------------------------- ### Get Filename from FilePath Source: https://github.com/madour/ldtkloader/wiki/DataTypes Retrieves the filename, including its extension, from a FilePath object. This method is const. ```c++ ldtk::FilePath::filename() const -> std::string ``` -------------------------------- ### Get IntGrid Tile Positions by Value Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the grid positions of IntGrid tiles matching a specific integer value. This is useful for locating tiles with a particular IntGrid value. ```c++ ldtk::Layer::getIntGridValPositions(int value) const -> const std::vector& ``` -------------------------------- ### Get Default Pivot Point Source: https://github.com/madour/ldtkloader/wiki/Project Returns the default pivot point for the project, which is a FloatPoint with values ranging from (0.f, 0.f) to (1.f, 1.f). ```c++ ldtk::Project::getDefaultPivot() const -> const ldtk::FloatPoint& ``` -------------------------------- ### Get Entity Definition by ID Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves an EntityDef by its unique integer ID. Throws an exception if no matching EntityDef is found. ```c++ ldtk::Project::getEntityDef(int id) const -> const ldtk::EntityDef& ``` -------------------------------- ### Get Tile Custom Data Source: https://github.com/madour/ldtkloader/wiki/Tileset Retrieves the custom string data associated with a specific tile ID. ```c++ ldtk::Tileset::getTileCustomData(int tile_id) const -> const std::string& ``` -------------------------------- ### Get Enum Icons Tileset Source: https://github.com/madour/ldtkloader/wiki/Enum Retrieve the Tileset used for an Enum's icons. This method is only relevant if the Enum has icons. ```cpp ldtk::Enum::getIconsTileset() const -> const ldtk::Tileset& ``` -------------------------------- ### Get File Path of Loaded Project Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves the file path from which the LDtk project was loaded. Returns a constant reference to the FilePath object. ```c++ ldtk::Project::getFilePath() const -> const ldtk::FilePath& ``` -------------------------------- ### Get Directory from FilePath Source: https://github.com/madour/ldtkloader/wiki/DataTypes Retrieves the directory path from a FilePath object. This method is const and does not modify the object. ```c++ ldtk::FilePath::directory() const -> std::string ``` -------------------------------- ### Get World Name Source: https://github.com/madour/ldtkloader/wiki/World Retrieves the name of the LDtk World. This method returns a constant reference to the string. ```c++ ldtk::World::getName() const -> const std::string& ``` -------------------------------- ### Get IntGrid Value Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the IntGrid value at a specific grid coordinate (x, y). Returns 'None' if no IntGrid value exists. ```c++ ldtk::Layer::getIntGridVal(int x, int y) const -> const IntGridValue& ``` -------------------------------- ### Get All Worlds Source: https://github.com/madour/ldtkloader/wiki/Project Returns a vector containing all the Worlds within the LDtk project. Each element is a reference to a ldtk::Project object representing a world. ```c++ ldtk::Project::allWorlds() const -> const std::vector& ``` -------------------------------- ### Basic CMake Configuration for LDtkLoader-raylib Source: https://github.com/madour/ldtkloader/blob/master/examples/Raylib/CMakeLists.txt Sets up the minimum CMake version, project name, and finds the raylib dependency. This is the foundational configuration for the project. ```cmake cmake_minimum_required(VERSION 3.10) if (POLICY CMP0074) cmake_policy(SET CMP0074 NEW) endif() project(LDtkLoader-raylib) ``` -------------------------------- ### Get IntGrid Tile Positions by Name Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the grid positions of IntGrid tiles matching a specific IntGrid value name. Use this when you need to find tiles based on their named IntGrid values. ```c++ ldtk::Layer::getIntGridValPositions(const std::string& name) const -> const std::vector& ``` -------------------------------- ### Get All World Levels Source: https://github.com/madour/ldtkloader/wiki/World Retrieves a vector containing all the levels within the World. Each element in the vector is an ldtk::Level object. ```c++ ldtk::World::allLevels() const -> const std::vector& ``` -------------------------------- ### Get World Layout Source: https://github.com/madour/ldtkloader/wiki/World Retrieves the layout of the World. The layout can be Free, GridVania, LinearHorizontal, or LinearVertical, as defined by the ldtk::WorldLayout enum. ```c++ ldtk::World::getLayout() const -> const ldtk::WorldLayout& ``` -------------------------------- ### Get Layer Definition by Name Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves a Layer Definition from the project using its string name. Throws an invalid_argument exception if no Layer Definition with the given name is found. ```c++ ldtk::Project::getLayerDef(const std::string& name) const -> const ldtk::LayerDef& ``` -------------------------------- ### Get Entity Position Relative to Layer Source: https://github.com/madour/ldtkloader/wiki/Entity Retrieves the position of the entity in pixels relative to its parent layer. To get the position relative to the level, add the layer's offset. ```c++ ldtk::Entity::getPosition() const -> const ldtk::IntPoint& ``` ```c++ auto entity_level_pos = entity.getPosition() + entity.layer->getOffset(); ``` -------------------------------- ### Load and Access LDtk Project Data Source: https://github.com/madour/ldtkloader/blob/master/README.md Demonstrates loading an LDtk project file, accessing worlds, levels, and layers, and iterating through tiles and entities. Shows how to retrieve entity fields and enum values. ```c++ // load the file ldtk::Project ldtk_project; ldtk_project.loadFromFile("my_project.ldtk"); // get a world const auto& world = ldtk_project.getWorld("MyWorld"); // get a level const auto& level1 = world.getLevel("Level1"); // get a layer const auto& bg_layer = level1.getLayer("BgLayer"); // iterate on the tiles of the layer for (const auto& tile : bg_layer.allTiles()) { // do something with the tile (storing, rendering ...) } // iterate on Enemy entities for (const ldtk::Entity& enemy : level1.getLayer("Entities").getEntitiesByName("Enemy")) { // iterate over an array field of Enum values for (const auto& item : enemy.getArrayField("items")) { // test if field is null if (!item.is_null()) { // do something with item if (item == world.getEnum("Items")["Sword"]) { // the enemy has a Sword ! } } } // get an Entity field int enemy_hp = enemy.getField("HP").value(); } ``` -------------------------------- ### Get Background Image Data from LDtk Level Source: https://github.com/madour/ldtkloader/wiki/Level Retrieves the background image data for the Level. This method returns a constant reference to the [[BgImage|BgImage#struct--ldtkBgImage]] structure. ```c++ ldtk::Level::getBgImage() const -> const ldtk::BgImage& ``` -------------------------------- ### Get Table of Contents Entities by Name Source: https://github.com/madour/ldtkloader/wiki/Project Returns a vector of EntityRefs with a specific name, located in the Table of Contents (ToC). ```c++ ldtk::Project::getTocEntitiesByName(const std::string& name) const -> const std::vector& ``` -------------------------------- ### Build LDtkLoader with CMake Source: https://github.com/madour/ldtkloader/blob/master/README.md Instructions for building the LDtkLoader static library using CMake. Specifies how to select build types (Debug/Release) and common CMake options. ```shell mkdir build && cd build cmake -DCMAKE_BUILD_TYPE={Debug|Release} .. cmake --build . --config {Debug|Release} ``` -------------------------------- ### Get Tiles by Enum Tag Source: https://github.com/madour/ldtkloader/wiki/Tileset Returns a vector of tile IDs that are tagged with a specific EnumValue. Throws an exception if the EnumValue type is incorrect. ```c++ ldtk::Tileset::getTilesByEnumTag(const ldtk::EnumValue& enumvalue) const -> const std::vector& ``` -------------------------------- ### Format Code with clang-format Source: https://github.com/madour/ldtkloader/blob/master/README.md Run clang-format to ensure code adheres to the project's style guidelines. This command recursively checks files in the 'src' and 'include' directories. ```shell python tools/run_clang_format.py -r src include ``` -------------------------------- ### Get World Level by ID or Name Source: https://github.com/madour/ldtkloader/wiki/World Retrieves a specific level from the World using its ID or name. Throws an invalid_argument exception if no matching level is found. ```c++ ldtk::World::getLevel(int id) const -> const ldtk::Level& ``` ```c++ ldtk::World::getLevel(const std::string& name) const -> const ldtk::Level& ``` -------------------------------- ### Get Entities by Name Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves a vector of reference wrappers for entities that match the provided name. When iterating, explicitly specify the entity type (e.g., `const ldtk::Entity&`) due to the use of reference wrappers. ```c++ ldtk::Layer::getEntitiesByName(const std::string& name) const -> const std::vector>& ``` ```c++ for (const ldtk::Entity& slime : layer.getEntitiesByName("Slime")) { // ... } ``` -------------------------------- ### Get File Extension from FilePath Source: https://github.com/madour/ldtkloader/wiki/DataTypes Extracts and returns only the file extension (e.g., 'png', 'json') from a FilePath object. This method is const. ```c++ ldtk::FilePath::extension() const -> std::string ``` -------------------------------- ### Default Constructor for ldtk::Project Source: https://github.com/madour/ldtkloader/wiki/Project Initializes a new instance of the ldtk::Project class. This is the default constructor. ```c++ ldtk::Project::Project() ``` -------------------------------- ### Get World Default Cell Size Source: https://github.com/madour/ldtkloader/wiki/World Retrieves the default cell size for the World grid. The cell dimensions are size x size. ```c++ ldtk::World::getDefaultCellSize() const -> int ``` -------------------------------- ### Load LDtk Project from File Path Source: https://github.com/madour/ldtkloader/wiki/Project Loads an LDtk project from a specified file path. Throws an exception if loading fails. All project data is loaded into the object upon successful execution. ```c++ ldtk::Project::LoadFromFile(const std::string& filepath) ``` -------------------------------- ### ldtk::Layer::getOffset Source: https://github.com/madour/ldtkloader/wiki/Layer Gets the total offset of the Layer in pixels. ```APIDOC ## ldtk::Layer::getOffset ### Description Returns Layer total offset in pixels. ### Method const ldtk::IntPoint& getOffset() const ### Returns The layer's offset in pixels. ``` -------------------------------- ### Get All Entities in Layer Source: https://github.com/madour/ldtkloader/wiki/Layer Fetches a vector containing all entities present in the layer. This method is useful for iterating through every entity within a layer. ```c++ ldtk::Layer::allEntities() const -> const std::vector& ``` -------------------------------- ### ldtk::Layer::getCellSize Source: https://github.com/madour/ldtkloader/wiki/Layer Gets the size of the grid cells in pixels. ```APIDOC ## ldtk::Layer::getCellSize ### Description Returns the size of grid cells (cell_size x cell_size). ### Method int getCellSize() const ### Returns The size of the grid cells in pixels. ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/madour/ldtkloader/blob/master/examples/API_test/CMakeLists.txt Defines the build settings for the LDtkLoader API test executable. This includes specifying the target, linking the LDtkLoader library, and setting up asset copying. ```cmake cmake_minimum_required(VERSION 3.10) project(LDtkLoader-API_test) add_executable(LDtkAPI_test main.cpp) target_link_libraries(LDtkAPI_test PRIVATE LDtkLoader) if (MSVC) target_compile_definitions(LDtkAPI_test PRIVATE _CRT_SECURE_NO_WARNINGS) endif() set_target_properties(LDtkAPI_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin) add_custom_command( TARGET LDtkAPI_test POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/assets/ $/assets/ ) ``` -------------------------------- ### Get Entity Sprite Texture Path Source: https://github.com/madour/ldtkloader/wiki/Entity Retrieves the file path to the texture of the entity's sprite. Returns an empty string if no sprite is present. ```c++ ldtk::Entity::getTexturePath() const -> const std::string& ``` -------------------------------- ### Get Layer Definition by ID Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves a Layer Definition from the project using its integer ID. Throws an invalid_argument exception if no Layer Definition with the given ID is found. ```c++ ldtk::Project::getLayerDef(int id) const -> const ldtk::LayerDef& ``` -------------------------------- ### Get Layer Offset Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the total offset of the layer in pixels from its origin. ```c++ ldtk::Layer::getOffset() const -> const ldtk::IntPoint& ``` -------------------------------- ### CMakeLists.txt for SFML Project Source: https://github.com/madour/ldtkloader/blob/master/examples/SFML/CMakeLists.txt This CMakeLists.txt file configures a project to use SFML for graphics and links it with the LDtkLoader library. It sets up the executable, links libraries, and defines a post-build command to copy assets. ```cmake cmake_minimum_required(VERSION 3.10) if (POLICY CMP0074) cmake_policy(SET CMP0074 NEW) endif() project(LDtkLoader-SFML) # find SFML find_package(SFML REQUIRED COMPONENTS graphics) add_executable(LDtkSFML main.cpp) target_link_libraries(LDtkSFML PRIVATE LDtkLoader sfml-graphics) set_target_properties(LDtkSFML PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin) add_custom_command( TARGET LDtkSFML POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/assets/ $/assets/ ) ``` -------------------------------- ### Get World Layer Definition by ID or Name Source: https://github.com/madour/ldtkloader/wiki/World Retrieves a specific layer definition from the World using its ID or name. Throws an invalid_argument exception if no matching layer definition is found. ```c++ ldtk::World::getLayerDef(int id) const -> const ldtk::LayerDef& ``` ```c++ ldtk::World::getLayerDef(const std::string& name) const -> const ldtk::LayerDef& ``` -------------------------------- ### Defining Executable and Linking Libraries Source: https://github.com/madour/ldtkloader/blob/master/examples/Raylib/CMakeLists.txt Defines the main executable target 'LDtkRaylib' from 'main.cpp' and links it with 'LDtkLoader' and 'raylib'. Sets the runtime output directory to 'bin'. ```cmake add_executable(LDtkRaylib main.cpp) target_link_libraries(LDtkRaylib PRIVATE LDtkLoader raylib) set_target_properties(LDtkRaylib PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin) ``` -------------------------------- ### Get Enum by Name Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves an Enum definition from the project using its string name. Throws an invalid_argument exception if no Enum with the given name is found. ```c++ ldtk::Project::getEnum(const std::string& name) const -> const ldtk::Enum& ``` -------------------------------- ### Constructor for FilePath from String Source: https://github.com/madour/ldtkloader/wiki/DataTypes Constructs a FilePath object from a provided string. Ensure the string represents a valid file path. ```c++ ldtk::FilePath::FilePath(const std::string&) ``` -------------------------------- ### Executable Target and Linking Source: https://github.com/madour/ldtkloader/blob/master/examples/SDL/CMakeLists.txt Defines the main executable 'LDtkSDL' from 'main.cpp' and links it with LDtkLoader, SDL2, and SDL2_image libraries. It also sets the output directory for the executable. ```cmake add_executable(LDtkSDL main.cpp) target_link_libraries(LDtkSDL PRIVATE LDtkLoader SDL2::SDL2 ${SDL2_IMAGE_LIBRARIES}) set_target_properties(LDtkSDL PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin) ``` -------------------------------- ### Get Enum by ID Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves an Enum definition from the project using its integer ID. Throws an invalid_argument exception if no Enum with the given ID is found. ```c++ ldtk::Project::getEnum(int id) const -> const ldtk::Enum& ``` -------------------------------- ### Get Cell Size Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the size of individual grid cells within the layer. ```c++ ldtk::Layer::getCellSize() const -> int ``` -------------------------------- ### Load LDtk Project from Memory (Raw Data) Source: https://github.com/madour/ldtkloader/wiki/Project Loads an LDtk project from a raw character data pointer and its size in memory. ```c++ ldtk::Project::loadFromMemory(const unsigned char* data, size_t size) ``` -------------------------------- ### Get World Entity Definition by ID or Name Source: https://github.com/madour/ldtkloader/wiki/World Retrieves a specific entity definition from the World using its ID or name. Throws an invalid_argument exception if no matching entity definition is found. ```c++ ldtk::World::getEntityDef(int id) const -> const ldtk::EntityDef& ``` ```c++ ldtk::World::getEntityDef(const std::string& name) const -> const ldtk::EntityDef& ``` -------------------------------- ### ldtk::Project::getBgColor Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves the default background color of the project. ```APIDOC ## ldtk::Project::getBgColor ### Description Returns the default background color of the Project. ### Method `ldtk::Project::getBgColor() const -> const ldtk::Color&` ### Returns - **ldtk::Color** - The default background color. ``` -------------------------------- ### Post-Build Asset Copy Command Source: https://github.com/madour/ldtkloader/blob/master/examples/SDL/CMakeLists.txt Adds a custom command to copy the 'assets' directory to the runtime output directory after the 'LDtkSDL' target is built. This ensures assets are available at runtime. ```cmake add_custom_command( TARGET LDtkSDL POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/assets/ $/assets/ ) ``` -------------------------------- ### Get Single World by Name Source: https://github.com/madour/ldtkloader/wiki/Project For projects with multi-world enabled, retrieves the World object that matches the provided string name. Throws an invalid_argument exception if no World with the given name is found. ```c++ ldtk::Project::getWorld(const std::string& name) const -> const ldtk::Project& ``` -------------------------------- ### ldtk::Project::loadFromFile Source: https://github.com/madour/ldtkloader/wiki/Project Loads a LDtk project from a given file path. This method can also be used with a custom file loader for virtual file systems. ```APIDOC ## ldtk::Project::loadFromFile ### Description Loads a LDtk project from a given file path. This overload allows loading a LDtk project using a custom stream, enabling loading from virtual filesystems. ### Method `ldtk::Project::loadFromFile(const std::string& filepath)` `ldtk::Project::loadFromFile(const std::string& filepath, const FileLoader& file_loader)` ### Parameters #### Path Parameters - **filepath** (string) - Required - The path to the LDtk project file. - **file_loader** (FileLoader) - Required - A custom file loader object (for the overloaded version). ### Throws Throws an exception in case of failure during loading. ``` -------------------------------- ### Default Constructor for FilePath Source: https://github.com/madour/ldtkloader/wiki/DataTypes Constructs an empty FilePath object. Use this when no initial file path is available. ```c++ ldtk::FilePath::FilePath() ``` -------------------------------- ### ldtk::Project::loadFromMemory Source: https://github.com/madour/ldtkloader/wiki/Project Loads a LDtk project from raw byte data in memory. ```APIDOC ## ldtk::Project::loadFromMemory ### Description Loads a LDtk project from a byte vector or raw character data in memory. ### Method `ldtk::Project::loadFromMemory(const std::vector& bytes)` `ldtk::Project::loadFromMemory(const unsigned char* data, size_t size)` ### Parameters #### Request Body - **bytes** (std::vector) - Required - A vector of bytes representing the LDtk project file. - **data** (const unsigned char*) - Required - A pointer to the raw byte data. - **size** (size_t) - Required - The size of the data in bytes. ``` -------------------------------- ### Load LDtk Project from Memory (Byte Vector) Source: https://github.com/madour/ldtkloader/wiki/Project Loads an LDtk project directly from a vector of unsigned 8-bit integers in memory. ```c++ ldtk::Project::loadFromMemory(const std::vector& bytes) ``` -------------------------------- ### Get Grid Size Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the dimensions of the layer's grid in terms of cell count. ```c++ ldtk::Layer::getGridSize() const -> const ldtk::IntPoint& ``` -------------------------------- ### Copying Assets Post-Build Source: https://github.com/madour/ldtkloader/blob/master/examples/Raylib/CMakeLists.txt Configures a custom command to copy the 'assets' directory from the current list directory to the assets directory within the runtime output of the 'LDtkRaylib' target after the build is complete. ```cmake add_custom_command( TARGET LDtkRaylib POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/assets/ $/assets/ ) ``` -------------------------------- ### ldtk::World::getBgColor Source: https://github.com/madour/ldtkloader/wiki/World Retrieves the default background color of the World. ```APIDOC ## getBgColor ### Description Returns the default background color of the World. ### Method const ldtk::Color& getBgColor() const ### Parameters None ### Response #### Success Response - **ldtk::Color&**: A const reference to the default background color of the World. ``` -------------------------------- ### ldtk::TileRect Source: https://github.com/madour/ldtkloader/wiki/DataTypes Represents a rectangle of tiles, used in TileField, with methods to get the associated tileset. ```APIDOC # Struct : `ldtk::TileRect` Represents a rectangle of one or multiple tiles. Used in TileField. * [Fields](#Fields) * [Methods](#Methods) ## Fields ### bounds ```c++ const IntRect ldtk::TileRect::bounds ``` ## Methods ### getTileset ```c++ ldtk::TileRect::getTileset() const -> const Tileset& ``` Returns the [[Tile|Tile#class--ldtkTile]]set to which the tile belongs. ``` -------------------------------- ### Load LDtk Project with Custom File Loader Source: https://github.com/madour/ldtkloader/wiki/Project Loads an LDtk project using a custom stream provided by a FileLoader. This overload is useful for loading from virtual filesystems. ```c++ ldtk::Project::loadFromFile(const std::string& filepath, const FileLoader& file_loader) ``` -------------------------------- ### Get Tile Enum Tags Source: https://github.com/madour/ldtkloader/wiki/Tileset Returns a vector of EnumValue references associated with a tile ID. ```c++ ldtk::Tileset::getTileEnumTags(int tile_id) const -> const std::vector>& ``` -------------------------------- ### Get Tile Texture Position Source: https://github.com/madour/ldtkloader/wiki/Tileset Returns the texture coordinates (IntPoint) for a given tile ID. ```c++ ldtk::Tileset::getTileTexturePos(int tile_id) const -> ldtk::IntPoint ``` -------------------------------- ### ldtk::BgImage Path Field Source: https://github.com/madour/ldtkloader/wiki/BgImage Represents the relative path to the background image file. ```c++ ldtk::FilePath ldtk::Level::BgImage::path ``` -------------------------------- ### Get All Enum Tags Source: https://github.com/madour/ldtkloader/wiki/Enum Retrieve a vector of all tags associated with an Enum. This functionality is inherited from TagsContainer. ```cpp ldtk::Enum::allTags() const -> const std::vector& ``` -------------------------------- ### ldtk::Project::allTilesets Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves all tilesets defined within the LDtk project. ```APIDOC ## ldtk::Project::allTilesets ### Description Returns a vector containing all the [[Tile|Tile#class--ldtkTile]]sets of the Project. ### Method `ldtk::Project::allTilesets() const -> const std::vector&` ### Returns - **std::vector** - A vector of all tilesets in the project. ``` -------------------------------- ### Apply Code Formatting Changes Source: https://github.com/madour/ldtkloader/blob/master/README.md Apply formatting changes to the code using clang-format. This command modifies files in place within the 'src' and 'include' directories. ```shell python tools/run_clang_format.py -i -r src include ``` -------------------------------- ### ldtk::BgImage Source: https://github.com/madour/ldtkloader/wiki/BgImage Contains information about the level's background image. ```APIDOC ## Struct : `ldtk::BgImage` Contains information about the background image of a level. ### Fields - [`path`](#path) - [`crop`](#crop) - [`pos`](#pos) - [`scale`](#scale) ### path ```c++ ldtk::FilePath ldtk::Level::BgImage::path ``` The relative path to the background image file. ### crop ```c++ ldtk::IntRect ldtk::Level::BgImage::crop ``` The cropped sub rectangle of the displayed image. ### pos ```c++ ldtk::IntPoint ldtk::Level::BgImage::pos ``` The position of the top left corner of the background image in the level. ### scale ```c++ ldtk::FloatPoint ldtk::Level::BgImage::scale ``` The scale of the background image. ``` -------------------------------- ### Get Enum Tags Enum Type Source: https://github.com/madour/ldtkloader/wiki/Tileset Retrieves the Enum type used for EnumTags within this tileset. ```c++ ldtk::Tileset::getEnumTagsEnum() const -> const Enum& ``` -------------------------------- ### Get EnumValue Icon Tileset Source: https://github.com/madour/ldtkloader/wiki/Enum Retrieve the Tileset for an EnumValue's icon. This is applicable only if the EnumValue has an icon. ```cpp ldtk::EnumValue::getIconTileset() const -> const ldtk::Tileset& ``` -------------------------------- ### Get Tileset from TileRect Source: https://github.com/madour/ldtkloader/wiki/DataTypes Retrieves the Tileset object associated with a TileRect. This is useful for understanding which tileset a tile belongs to. ```c++ ldtk::TileRect::getTileset() const -> const Tileset& ``` -------------------------------- ### ldtk::Tile Methods Source: https://github.com/madour/ldtkloader/wiki/Tile Provides methods to retrieve the position, texture rectangle, and vertex data of a tile. ```APIDOC ## Methods ### getPosition ```c++ ldtk::Tile::getPosition() const -> ldtk::IntPoint ``` Returns the position of the Tile in pixels, relatively to the [[Level|Level#class--ldtkLevel]] (i.e. after applying [[Layer|Layer#class--ldtkLayer]] offset). ### getGridPosition ```c++ ldtk::Tile::getGridPosition() const -> ldtk::IntPoint ``` Returns the grid position of the Tile. ### getWorldPosition ```c++ ldtk::Tile::getWorldPosition() const -> ldtk::IntPoint ``` Returns the position of the Tile in pixels, relatively to the World (i.e. after applying [[Layer|Layer#class--ldtkLayer]] and [[Level|Level#class--ldtkLevel]] offsets). ### getTextureRect ```c++ ldtk::Tile::getTextureRect() const -> ldtk::IntRect ``` Returns the Int[[Rect|DataTypes#struct--ldtkRectT]] corresponding to the Tile area on the [[Tileset|Tileset#class--ldtkTileset]] texture. ### getVertices ```c++ ldtk::Tile::getVertices() const -> std::array ``` Returns an array containing 4 vertices, corresponding the graphical representation of a Tile quad. See [[Vertex|DataTypes#struct--ldtkVertex]]. ``` -------------------------------- ### Get Tile ID at Position Source: https://github.com/madour/ldtkloader/wiki/Tileset Returns the tile ID at the given pixel coordinates within the tileset texture. ```c++ ldtk::Tileset::getTileIdAt(int pos_x, int pos_y) const -> int ``` -------------------------------- ### ldtk::Tile::getGridPosition Method Source: https://github.com/madour/ldtkloader/wiki/Tile Retrieves the grid-based position of the tile. ```c++ ldtk::Tile::getGridPosition() const -> ldtk::IntPoint ``` -------------------------------- ### Get All Entity Tags Source: https://github.com/madour/ldtkloader/wiki/Entity Retrieves a vector containing all tags assigned to the entity. This is useful for iterating through all categories an entity belongs to. ```c++ ldtk::Entity::allTags() const -> const std::vector& ``` -------------------------------- ### ldtk::Tileset Methods Source: https://github.com/madour/ldtkloader/wiki/Tileset Provides methods to query tile information, texture positions, custom data, and enum tag associations for a given tileset. ```APIDOC ## Methods ### getTileIdAt - **Description**: Returns the tile id at the given position in pixels. - **Signature**: `ldtk::Tileset::getTileIdAt(int pos_x, int pos_y) const -> int` ### getTileTexturePos - **Description**: Returns the texture coordinates of the tile ID. - **Signature**: `ldtk::Tileset::getTileTexturePos(int tile_id) const -> ldtk::IntPoint` ### getTileCustomData - **Description**: Returns the custom data associated with the tile ID. - **Signature**: `ldtk::Tileset::getTileCustomData(int tile_id) const -> const std::string&` ### getTileEnumTags - **Description**: Returns a vector containing the EnumTags associated with the tile ID. - **Signature**: `ldtk::Tileset::getTileEnumTags(int tile_id) const -> const std::vector>&` ### hasEnumTags - **Description**: Returns `true` if the tileset has enum tags associated to tiles, `false` otherwise. - **Signature**: `ldtk::Tileset::hasEnumTags() const -> bool` ### getEnumTagsEnum - **Description**: Returns the Enum type used by this tileset's EnumTags. - **Signature**: `ldtk::Tileset::getEnumTagsEnum() const -> const Enum&` ### getTilesByEnumTag - **Description**: Get a vector of all tiles ID tagged with a given EnumValue. Throws an `invalid_argument` exception if the EnumValue argument does not have the right Enum type. - **Signature**: `ldtk::Tileset::getTilesByEnumTag(const ldtk::EnumValue& enumvalue) const -> const std::vector&` ### hasTag - **Description**: Returns `true` if the tileset contains the given tag, returns `false` otherwise. Inherited from `TagsContainer`. - **Signature**: `ldtk::Tileset::hasTag(const std::string&) const -> bool` ### allTags - **Description**: Returns a vector containing all the tags in the tileset. Inherited from `TagsContainer`. - **Signature**: `ldtk::Tileset::allTags() const -> const std::vector&` ``` -------------------------------- ### ldtk::Project::getFilePath Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves the file path from which the LDtk project was loaded. ```APIDOC ## ldtk::Project::getFilePath ### Description Returns the path of the file from which the Project was loaded. ### Method `ldtk::Project::getFilePath() const -> const ldtk::FilePath&` ### Returns - **ldtk::FilePath** - The path of the loaded LDtk project file. ``` -------------------------------- ### ldtk::World::allLevels Source: https://github.com/madour/ldtkloader/wiki/World Retrieves all levels contained within the World. ```APIDOC ## allLevels ### Description Returns a vector containing all the [[Level|Level#class--ldtkLevel]]s of the World. ### Method const std::vector& allLevels() const ### Parameters None ### Response #### Success Response - **std::vector&**: A const reference to a vector of all Levels in the World. ``` -------------------------------- ### ldtk::Project::getWorld Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves a world by its name, or the single world if the project has only one. ```APIDOC ## ldtk::Project::getWorld ### Description For Projects with only one world, returns that [[World|World#class--ldtkWorld]]. For multi-world projects, returns the [[World|World#class--ldtkWorld]] matching the given `name`. Throws an `invalid_argument` exception if the project has multiple worlds and no name is provided, or if no world with the specified name is found. ### Method `ldtk::Project::getWorld() const -> const ldtk::Project&` `ldtk::Project::getWorld(const std::string& name) const -> const ldtk::Project&` ### Parameters #### Path Parameters - **name** (string) - Required (for multi-world projects) - The name of the world to retrieve. ### Returns - **ldtk::Project** - The requested world. ### Throws Throws an `invalid_argument` exception if the project has multiple worlds and no name is provided, or if no world with the specified name is found. ``` -------------------------------- ### Get Entity World Position Source: https://github.com/madour/ldtkloader/wiki/Entity Retrieves the computed position of the entity in pixels relative to the world origin. This accounts for all parent offsets. ```c++ ldtk::Entity::getWorldPosition() const -> const ldtk::IntPoint& ``` -------------------------------- ### Analyze Code with clang-tidy Source: https://github.com/madour/ldtkloader/blob/master/README.md Use clang-tidy to identify coding mistakes and code smells. This command analyzes C++ source files in the 'src' directory, considering include paths from 'include' and 'build/include'. ```shell clang-tidy --config-file=.clang-tidy src/*.cpp -- -I include -I build/include ``` -------------------------------- ### ldtk::FilePath Source: https://github.com/madour/ldtkloader/wiki/DataTypes Represents a file path with methods to access its directory, filename, and extension. ```APIDOC ## Class : `ldtk::FilePath` A string that contains file path information. ### Constructor ```c++ ldtk::FilePath::FilePath() ``` Default constructor. Constructs an empty FilePath. ```c++ ldtk::FilePath::FilePath(const std::string&) ``` Construct a FilePath from a valid provided string. ### Methods #### directory ```c++ ldtk::FilePath::directory() const -> std::string ``` Returns the path to the directory containing the file. #### filename ```c++ ldtk::FilePath::filename() const -> std::string ``` Returns the filename (including the extension) of the FilePath. #### extension ```c++ ldtk::FilePath::extension() const -> std::string ``` Returns only the extension of the file (e.g. png, json, txt ...). ``` -------------------------------- ### ldtk::Layer::getOpacity Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the opacity of the Layer. ```APIDOC ## ldtk::Layer::getOpacity ### Description Returns Layer opacity. ### Method float getOpacity() const ### Returns The opacity of the layer. ``` -------------------------------- ### Get Entity 9-Slice Borders Source: https://github.com/madour/ldtkloader/wiki/Entity Retrieves the border definitions for the entity's 9-slice sprite. These values define how the sprite is divided for scaling. ```c++ ldtk::Entity::getNineSliceBorders() const -> const ldtk::NineSliceBorders& ``` -------------------------------- ### ldtk::World::allTilesets Source: https://github.com/madour/ldtkloader/wiki/World Retrieves all tilesets associated with the World. ```APIDOC ## allTilesets ### Description Returns a vector containing all the [[Tile|Tile#class--ldtkTile]]sets of the World. ### Method const std::vector& allTilesets() const ### Parameters None ### Response #### Success Response - **std::vector&**: A const reference to a vector of all Tilesets in the World. ``` -------------------------------- ### getIntGridValPositions (by value) Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the grid positions of all tiles matching a specific IntGrid value. ```APIDOC ## getIntGridValPositions (by value) ### Description Returns a vector containing the grid positions of all tiles of the given IntGridValue value. ### Method const std::vector& getIntGridValPositions(int value) const ### Parameters #### Path Parameters - **value** (int) - Required - The IntGridValue to search for. ### Response #### Success Response - **std::vector** - A vector of IntPoint structs representing the grid positions. ``` -------------------------------- ### Get LDtk Field Value Source: https://github.com/madour/ldtkloader/wiki/Fields Retrieves the actual value stored within an LDtk field. This method should be used when you are certain the field is not null. ```c++ constexpr value() const -> const T& ``` -------------------------------- ### Get Array Field (Point) Source: https://github.com/madour/ldtkloader/wiki/Entity Retrieves an array field of type Point from a level. Iterates through the array, checking each element for null before accessing its value. ```c++ const auto& array_field = level.getField("spawns"); for (const auto& field : array_field) { if (!field.is_null()) { const auto& point = field.value(); } } ``` -------------------------------- ### ldtk::Project::allWorlds Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves all worlds defined within the LDtk project. ```APIDOC ## ldtk::Project::allWorlds ### Description Returns a vector containing all the [[World|World#class--ldtkWorld]]s of the Project. ### Method `ldtk::Project::allWorlds() const -> const std::vector&` ### Returns - **std::vector** - A vector of all worlds in the project. ``` -------------------------------- ### Get Entity Pivot Source: https://github.com/madour/ldtkloader/wiki/Entity Retrieves the pivot point of the entity, normalized to a range of (0.0, 0.0) to (1.0, 1.0). The pivot defines the origin for transformations. ```c++ ldtk::Entity::getPivot() const -> const ldtk::FloatPoint& ``` -------------------------------- ### getIntGridValPositions (by name) Source: https://github.com/madour/ldtkloader/wiki/Layer Retrieves the grid positions of all tiles matching a specific IntGrid value name. ```APIDOC ## getIntGridValPositions (by name) ### Description Returns a vector containing the grid positions of all tiles of the given IntGridValue name. ### Method const std::vector& getIntGridValPositions(const std::string& name) const ### Parameters #### Path Parameters - **name** (string) - Required - The name of the IntGridValue to search for. ### Response #### Success Response - **std::vector** - A vector of IntPoint structs representing the grid positions. ``` -------------------------------- ### ldtk::World::getLayout Source: https://github.com/madour/ldtkloader/wiki/World Retrieves the layout of the world, which can be Free, GridVania, LinearHorizontal, or LinearVertical. ```APIDOC ## getLayout ### Description Returns the layout of the world (Free, GridVania, LinearHorizontal or LinearVertical). See [[WorldLayout|DataTypes#enum--ldtkWorldLayout]] enum. ### Method const ldtk::WorldLayout& getLayout() const ### Parameters None ### Response #### Success Response - **ldtk::WorldLayout&**: A const reference to the world's layout. ``` -------------------------------- ### ldtk::Project::getDefaultPivot Source: https://github.com/madour/ldtkloader/wiki/Project Retrieves the default pivot point for the project. ```APIDOC ## ldtk::Project::getDefaultPivot ### Description Returns the default pivot, a point from (0.f, 0.f) to (1.f, 1.f). ### Method `ldtk::Project::getDefaultPivot() const -> const ldtk::FloatPoint&` ### Returns - **ldtk::FloatPoint** - The default pivot point. ```