From 988c12415ac8b1f99c8138c9c136602a2cd54f54 Mon Sep 17 00:00:00 2001 From: kdx Date: Tue, 23 Jan 2024 15:32:14 +0100 Subject: internal tile objectgroup --- src/main.c | 20 +++++++++++++++++--- tiled2c.h | 32 +++++++++++++++++--------------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/main.c b/src/main.c index a35ff7e..c5accb1 100644 --- a/src/main.c +++ b/src/main.c @@ -118,7 +118,7 @@ process_object(cJSON *json) JSON_GET(json, height); JSON_GET(json, rotation); JSON_GET(json, visible); - printf("{\"%s\",\"%s\",%d,%d,%d,%d,%d,%d,%f,%d,", + printf("{\"%s\",\"%s\",%d,%d,%d,%d,%d,%d,%f,%d", name->valuestring, type->valuestring, id->valueint, @@ -130,9 +130,9 @@ process_object(cJSON *json) cJSON *properties = cJSON_GetObjectItem(json, "properties"); if (!cJSON_IsArray(properties) || cJSON_GetArraySize(properties) == 0) - printf("0,0"); + printf(",0,0"); else { - printf("%d,(const Tiled2cProperty[]){", + printf(",%d,(const Tiled2cProperty[]){", cJSON_GetArraySize(properties)); cJSON *property; cJSON_ArrayForEach(property, properties) { @@ -270,6 +270,20 @@ process_tile(cJSON *json) printf("}"); } + cJSON *objectgroup = cJSON_GetObjectItem(json, "objectgroup"); + if (!cJSON_IsObject(objectgroup)) + printf(",0,0"); + else { + JSON_GET_ARRAY(objectgroup, objects); + printf(",%d,(const Tiled2cObject[]){", cJSON_GetArraySize(objects)); + cJSON *object; + cJSON_ArrayForEach(object, objects) { + if (process_object(object) < 0) + return -1; + } + printf("}"); + } + printf("},"); return 0; } diff --git a/tiled2c.h b/tiled2c.h index 9ad79a8..e6fb692 100644 --- a/tiled2c.h +++ b/tiled2c.h @@ -15,6 +15,21 @@ typedef struct { double valuenumber; } Tiled2cProperty; +typedef struct { + const char *name; + const char *type; + unsigned int id; + unsigned int tile; + double x; + double y; + double width; + double height; + double rotation; + unsigned int visible; + unsigned int numproperties; + const Tiled2cProperty *properties; +} Tiled2cObject; + typedef struct { unsigned int id; const char *type; @@ -23,6 +38,8 @@ typedef struct { const Tiled2cFrame *frames; unsigned int numproperties; const Tiled2cProperty *properties; + unsigned int numobjects; + const Tiled2cObject *objects; } Tiled2cTile; typedef struct { @@ -63,21 +80,6 @@ typedef struct { }; } Tiled2cLayer; -typedef struct { - const char *name; - const char *type; - unsigned int id; - unsigned int tile; - double x; - double y; - double width; - double height; - double rotation; - unsigned int visible; - unsigned int numproperties; - const Tiled2cProperty *properties; -} Tiled2cObject; - typedef struct { const char *path; unsigned int width; -- cgit v1.2.3