Update cute_tiled.h

This commit is contained in:
2023-11-08 16:40:20 +01:00
parent efada40908
commit e56c2a067e
2 changed files with 44 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
#include <breeze/core/logger.h>
#include <breeze/core/memory.h>
#if 1
#define CUTE_TILED_WARNING(msg) bzLogWarning(msg)
#define CUTE_TILED_ALLOC(size, ctx) bzAlloc(size)
@@ -8,5 +10,7 @@
#define CUTE_TILED_MEMCPY bzMemCpy
#define CUTE_TILED_MEMSET bzMemSet
#endif
#define CUTE_TILED_IMPLEMENTATION
#include "cute_tiled.h"

View File

@@ -105,6 +105,8 @@
#if !defined(CUTE_TILED_H)
#include <stdint.h> // uint32_t
// Read this in the event of errors
extern const char* cute_tiled_error_reason;
extern int cute_tiled_error_line;
@@ -305,6 +307,7 @@ static CUTE_TILED_INLINE void cute_tiled_get_flags(int tile_data_gid, int* flip_
struct cute_tiled_layer_t
{
/* chunks */ // Not currently supported.
cute_tiled_string_t class_; // The class of the layer (since 1.9, optional).
/* compression; */ // Not currently supported.
int data_count; // Number of integers in `data`.
int* data; // Array of GIDs. `tilelayer` only. Only support CSV style exports.
@@ -319,8 +322,8 @@ struct cute_tiled_layer_t
float opacity; // Value between 0 and 1.
int property_count; // Number of elements in the `properties` array.
cute_tiled_property_t* properties; // Array of properties.
int transparentcolor; // Hex-formatted color (#RRGGBB or #AARRGGBB) (optional).
int tintcolor; // Hex-formatted color (#RRGGBB or #AARRGGBB) (optional).
uint32_t transparentcolor; // Hex-formatted color (#AARRGGBB) (optional).
uint32_t tintcolor; // Hex-formatted color (#AARRGGBB) (optional).
cute_tiled_string_t type; // `tilelayer`, `objectgroup`, `imagelayer` or `group`.
cute_tiled_string_t image; // An image filepath. Used if layer is type `imagelayer`.
int visible; // 0 or 1. Whether layer is shown or hidden in editor.
@@ -371,6 +374,7 @@ struct cute_tiled_tile_descriptor_t
struct cute_tiled_tileset_t
{
int backgroundcolor; // Hex-formatted color (#RRGGBB or #AARRGGBB) (optional).
cute_tiled_string_t class_; // The class of the tileset (since 1.9, optional).
int columns; // The number of tile columns in the tileset.
int firstgid; // GID corresponding to the first tile in the set.
/* grid */ // Not currently supported.
@@ -391,7 +395,7 @@ struct cute_tiled_tileset_t
int tileoffset_y; // Pixel offset to align tiles to the grid.
cute_tiled_tile_descriptor_t* tiles; // Linked list of tile descriptors. Can be NULL.
int tilewidth; // Maximum width of tiles in this set.
int transparentcolor; // Hex-formatted color (#RRGGBB or #AARRGGBB) (optional).
uint32_t transparentcolor; // Hex-formatted color (#AARRGGBB) (optional).
cute_tiled_string_t type; // `tileset` (for tileset files, since 1.0).
cute_tiled_string_t source; // Relative path to tileset, when saved externally from the map file.
cute_tiled_tileset_t* next; // Pointer to next tileset. NULL if final tileset.
@@ -402,6 +406,7 @@ struct cute_tiled_tileset_t
struct cute_tiled_map_t
{
int backgroundcolor; // Hex-formatted color (#RRGGBB or #AARRGGBB) (optional).
cute_tiled_string_t class_; // The class of the map (since 1.9, optional).
int height; // Number of tile rows.
/* hexsidelength */ // Not currently supported.
int infinite; // Whether the map has infinite dimensions.
@@ -1639,8 +1644,22 @@ static int cute_tiled_read_hex_int_internal(cute_tiled_map_internal_t* m, int* o
val = CUTE_TILED_STRTOULL(m->in, &end, 16);
CUTE_TILED_CHECK(m->in != end, "Invalid integer found during parse.");
// Count the length to determine if we need to force AARRGGBB, instead of RRGGBB.
int length = 0;
while (m->in != end) {
m->in++;
length++;
}
*out = (uint32_t)val;
// When less than 6 characters, force an alpha channel of 0xFF.
if (length <= 6) {
uint32_t alpha = 0xFF << 24;
*out = (*out & 0x00FFFFFF) | alpha;
}
m->in = end;
*out = (int)val;
return 1;
cute_tiled_err:
@@ -2066,9 +2085,8 @@ cute_tiled_object_t* cute_tiled_read_object(cute_tiled_map_internal_t* m)
break;
case 1485919047363370797U: // class
CUTE_TILED_WARNING("Class field of Tiled objects is not yet supported. Ignoring field.");
while (cute_tiled_peak(m) != ',' && cute_tiled_peak(m) != '}') cute_tiled_next(m);
if (cute_tiled_peak(m) == '}') continue;
// This is technically different than type, but it used the same way in newer versions of Tiled
cute_tiled_intern_string(m, &object->type);
break;
default:
@@ -2105,6 +2123,10 @@ cute_tiled_layer_t* cute_tiled_layers(cute_tiled_map_internal_t* m)
switch (h)
{
case 1485919047363370797U: // class
cute_tiled_intern_string(m, &layer->class_);
break;
case 14868627273436340303U: // compression
CUTE_TILED_CHECK(0, "Compression is not yet supported. The expected tile format is CSV (uncompressed). Please see the docs if you are interested in compression.");
break;
@@ -2453,6 +2475,10 @@ cute_tiled_tileset_t* cute_tiled_tileset(cute_tiled_map_internal_t* m)
cute_tiled_expect(m, '"');
break;
case 1485919047363370797U: // class
cute_tiled_intern_string(m, &tileset->class_);
break;
case 12570673734542705940U: // columns
cute_tiled_read_int(m, &tileset->columns);
break;
@@ -2607,6 +2633,10 @@ static int cute_tiled_dispatch_map_internal(cute_tiled_map_internal_t* m)
cute_tiled_expect(m, '"');
break;
case 1485919047363370797U: // class
cute_tiled_intern_string(m, &m->map.class_);
break;
case 5549108793316760247U: // compressionlevel
{
int compressionlevel;
@@ -2741,6 +2771,7 @@ static void cute_tiled_deintern_layer(cute_tiled_map_internal_t* m, cute_tiled_l
while (layer)
{
cute_tiled_object_t* object;
cute_tiled_deintern_string(m, &layer->class_);
cute_tiled_deintern_string(m, &layer->draworder);
cute_tiled_deintern_string(m, &layer->name);
cute_tiled_deintern_string(m, &layer->type);
@@ -2765,6 +2796,7 @@ static void cute_tiled_deintern_layer(cute_tiled_map_internal_t* m, cute_tiled_l
static void cute_tiled_patch_tileset_strings(cute_tiled_map_internal_t* m, cute_tiled_tileset_t* tileset)
{
cute_tiled_tile_descriptor_t* tile_descriptor;
cute_tiled_deintern_string(m, &tileset->class_);
cute_tiled_deintern_string(m, &tileset->image);
cute_tiled_deintern_string(m, &tileset->name);
cute_tiled_deintern_string(m, &tileset->type);
@@ -2786,6 +2818,7 @@ static void cute_tiled_patch_interned_strings(cute_tiled_map_internal_t* m)
{
cute_tiled_tileset_t* tileset;
cute_tiled_layer_t* layer;
cute_tiled_deintern_string(m, &m->map.class_);
cute_tiled_deintern_string(m, &m->map.orientation);
cute_tiled_deintern_string(m, &m->map.renderorder);
cute_tiled_deintern_string(m, &m->map.tiledversion);