LibTMJ
1.0.0
A library for loading JSON Tiled maps
|
A library for loading Tiled maps in JSON format
Bear in mind that this library is relatively new. If you find bugs, or find that the library is missing an important feature, please file an issue.
jansson
zlib
(Optional, for zlib and gzip decompression support)zstd
(Optional, for zstd decompression support)Doxygen
(Optional, for building documentation)Graphviz
(Optional, for drawing graphs in the generated docs)To build in Windows, use vcpkg to fetch and install the above dependencies:
From the repository root, run:
For Windows users, make sure to include the vcpkg toolchain file:
Available cmake build options:
Option | Description |
---|---|
BUILD_SHARED_LIBS | Builds a shared library instead of a static library. |
CMAKE_BUILD_TYPE | One of "Release" (optimization) or "Debug" (runtime sanitizers + debug symbols) |
LIBTMJ_DOCS | Also build documentation. |
LIBTMJ_ZSTD | Build zstd decompression routines. |
LIBTMJ_ZLIB | Build zlib and gzip decompression routines. |
LIBTMJ_TEST | Build the test suite. |
If you're going to build and run tests, don't forget to pull the Unity submodule:
To enable the test suite, invoke cmake with:
Then run the tests with:
Below is a brief example of how to use libtmj. For more detail, see the API documentation. Specifically, refer to the Data Structures page for a list of fields provided by each structure. They match the names given in the Tiled documentation, with the exception of added fields which give the number of elements in array fields, whose names are {field}_count
(as shown below for the "layer" field).
JSON only defines a single number type, meant to accomodate both floating point values and integers of arbitrary length. This library truncates all input integers to the size of int
on your platform, and all input floating point numbers to the size of double
on your platform. My estimation is that this is acceptable for a Tiled map. If you find a case in which this breaks your map, please let me know.
BSD 2-Clause License Copyright (c) 2023-2024, David Zero All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.