LibTMJ  1.0.0
A library for loading JSON Tiled maps
Typedefs | Enumerations | Functions | Variables
TMJ

Public API for loading JSON-formatted Tiled maps and tilesets. More...

Typedefs

typedef enum TMJ_LOG_PRIORITY tmj_log_priority
 

Enumerations

enum  TMJ_LOG_PRIORITY {
  TMJ_LOG_DEBUG , TMJ_LOG_INFO , TMJ_LOG_WARNING , TMJ_LOG_ERR ,
  TMJ_LOG_CRIT
}
 

Functions

Maptmj_map_loadf (const char *path, bool check_extension)
 Loads the Tiled map from the file at the given path. More...
 
Maptmj_map_load (const char *map, const char *name)
 Loads the Tiled map from the given JSON object string. More...
 
Tilesettmj_tileset_loadf (const char *path, bool check_extension)
 Loads the Tiled tileset at the given path. More...
 
Tilesettmj_tileset_load (const char *tileset)
 Loads the Tiled tileset from the given JSON object string. More...
 
void tmj_map_free (Map *map)
 Frees the memory associated with the given map. More...
 
void tmj_tileset_free (Tileset *tileset)
 Frees the memory associated with the given tileset. More...
 
void tmj_log_regcb (bool debug, void(*callback)(tmj_log_priority, const char *))
 Registers a callback function to handle logging events. More...
 
uint32_t * tmj_decode_layer (const char *data, const char *encoding, const char *compression, size_t *size)
 Decodes layer data from a Tiled map layer. More...
 

Variables

const unsigned int TMJ_VERSION_MAJOR
 ‍** More...
 
const unsigned int TMJ_VERSION_MINOR
 The library minor version. More...
 
const unsigned int TMJ_VERSION_PATCH
 The library patch version. More...
 
const char *const TMJ_VERSION
 The full library version. More...
 

Detailed Description

Public API for loading JSON-formatted Tiled maps and tilesets.

Typedef Documentation

◆ tmj_log_priority

Enumeration Type Documentation

◆ TMJ_LOG_PRIORITY

Enumerator
TMJ_LOG_DEBUG 
TMJ_LOG_INFO 
TMJ_LOG_WARNING 
TMJ_LOG_ERR 
TMJ_LOG_CRIT 

Definition at line 496 of file tmj.h.

Function Documentation

◆ tmj_map_loadf()

Map* tmj_map_loadf ( const char *  path,
bool  check_extension 
)

Loads the Tiled map from the file at the given path.

The map object returned by this function must not be modified by the caller.

Parameters
pathA relative or absolute filesystem path.
check_extensionIf true, validates that the file extension equals ".tmj" or ".json".
Returns
On success, returns a pointer to a map. The map is dynamically-allocated, and must be freed by the caller using map_free(). On failure, returns NULL.

Definition at line 1088 of file map.c.

Here is the call graph for this function:

◆ tmj_map_load()

Map* tmj_map_load ( const char *  map,
const char *  name 
)

Loads the Tiled map from the given JSON object string.

The map object returned by this function must not be modified by the caller.

Parameters
mapA JSON string containing a Tiled map object.
nameA name to use to reference this map in log messages. tmj_map_loadf() does not require this argument, because it uses the file path to identify the map in log messages.
Returns
On success, returns a pointer to a map. The map is dynamically-allocated, and must be freed by the caller using map_free(). On failure, returns NULL.

Definition at line 1120 of file map.c.

Here is the call graph for this function:

◆ tmj_tileset_loadf()

Tileset* tmj_tileset_loadf ( const char *  path,
bool  check_extension 
)

Loads the Tiled tileset at the given path.

The tileset object returned by this function must not be modified by the caller.

Parameters
pathA relative or absolute filesystem path.
check_extensionIf true, validates that the file extension equals ".tsj" or ".json".
Returns
On success, returns a pointer to a tileset. The tileset is dynamically-allocated, and must be freed by the caller using tileset_free(). On failure, returns NULL.

Definition at line 588 of file tileset.c.

Here is the call graph for this function:

◆ tmj_tileset_load()

Tileset* tmj_tileset_load ( const char *  tileset)

Loads the Tiled tileset from the given JSON object string.

The tileset object returned by this function must not be modified by the caller.

Parameters
tilesetA JSON string containing a Tiled tileset object.
Returns
On success, returns a pointer to a tileset. The tileset is dynamically-allocated, and must be freed by the caller using tileset_free(). On failure, returns NULL.

Definition at line 638 of file tileset.c.

Here is the call graph for this function:

◆ tmj_map_free()

void tmj_map_free ( Map map)

Frees the memory associated with the given map.

If the map was modified by the caller, this function may cause undefined behavior.

Parameters
mapA map which was returned by a call to map_load().

Definition at line 1134 of file map.c.

Here is the call graph for this function:

◆ tmj_tileset_free()

void tmj_tileset_free ( Tileset tileset)

Frees the memory associated with the given tileset.

If the tileset was modified by the caller, this function may cause undefined behavior.

Parameters
tilesetA tileset which was returned by a call to tileset_load().

Definition at line 671 of file tileset.c.

Here is the call graph for this function:

◆ tmj_log_regcb()

void tmj_log_regcb ( bool  debug,
void(*)(tmj_log_priority, const char *)  callback 
)

Registers a callback function to handle logging events.

Parameters
debugIf set to true, the given callback function will receive debug messages and information in addition to the higher-priority messages.
callbackA function that takes a TMJ_LOG_PRIORITY and a char* and returns nothing.

Definition at line 18 of file log.c.

◆ tmj_decode_layer()

uint32_t* tmj_decode_layer ( const char *  data,
const char *  encoding,
const char *  compression,
size_t *  size 
)

Decodes layer data from a Tiled map layer.

Parameters
dataThe value of the "data_str" field from a Layer.
encodingThe value of the "encoding" field from a Layer.
compressionThe value of the "compression" field from a Layer.
[out]sizeThe size of the resultant integer array.
Returns
On Success, returns a dynamically-allocated array of global tile IDs. This array must be freed by the caller. See https://doc.mapeditor.org/en/stable/reference/global-tile-ids/ for more information. On failure, returns NULL.

Definition at line 15 of file util.c.

Here is the call graph for this function:

Variable Documentation

◆ TMJ_VERSION_MAJOR

const unsigned int TMJ_VERSION_MAJOR
extern

‍**

The library major version.

An unsigned integer representing the major component of the SemVer 2.0 version of this library.

Definition at line 10 of file util.c.

◆ TMJ_VERSION_MINOR

const unsigned int TMJ_VERSION_MINOR
extern

The library minor version.

An unsigned integer representing the minor component of the SemVer 2.0 version of this library.

Definition at line 11 of file util.c.

◆ TMJ_VERSION_PATCH

const unsigned int TMJ_VERSION_PATCH
extern

The library patch version.

An unsigned integer representing the patch component of the SemVer 2.0 version of this library.

Definition at line 12 of file util.c.

◆ TMJ_VERSION

const char* const TMJ_VERSION
extern

The full library version.

A string containing the full SemVer 2.0 version of this library.

Definition at line 13 of file util.c.