diff options
author | kdx <kikoodx@paranoici.org> | 2024-01-23 15:32:14 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2024-01-23 15:32:14 +0100 |
commit | 988c12415ac8b1f99c8138c9c136602a2cd54f54 (patch) | |
tree | 85912aa5b81502ca2b21cc566163add3188dbdea | |
parent | 7e27aed0f603c26a853ef5d2c630505a79318227 (diff) | |
download | tiled2c-988c12415ac8b1f99c8138c9c136602a2cd54f54.tar.gz |
internal tile objectgroup
-rw-r--r-- | src/main.c | 20 | ||||
-rw-r--r-- | tiled2c.h | 32 |
2 files changed, 34 insertions, 18 deletions
@@ -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; } @@ -16,6 +16,21 @@ typedef struct { } 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; double probability; @@ -23,6 +38,8 @@ typedef struct { const Tiled2cFrame *frames; unsigned int numproperties; const Tiled2cProperty *properties; + unsigned int numobjects; + const Tiled2cObject *objects; } Tiled2cTile; typedef struct { @@ -64,21 +81,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; unsigned int height; |