diff --git a/cute_tiled.h b/cute_tiled.h index 762e8e48..6e1677bd 100644 --- a/cute_tiled.h +++ b/cute_tiled.h @@ -105,6 +105,8 @@ #if !defined(CUTE_TILED_H) +#include // uint32_t + // Read this in the event of errors extern const char* cute_tiled_error_reason; extern int cute_tiled_error_line; @@ -320,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. @@ -393,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. @@ -1642,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: