diff options
author | kdx <kikoodx@paranoici.org> | 2023-09-12 12:06:31 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-09-12 12:19:27 +0200 |
commit | 1ff165df318c97fa0d9a4803a5c5149e0896f2ba (patch) | |
tree | 4852ccb24d21801f232160b7670ca5228901ef9f | |
parent | ada8e5fd4a6315bf3e6368862477353b1d13c3bb (diff) | |
download | tiled2c-1ff165df318c97fa0d9a4803a5c5149e0896f2ba.tar.gz |
add support for object properties
-rw-r--r-- | src/main.c | 30 | ||||
-rw-r--r-- | tiled2c.h | 103 |
2 files changed, 86 insertions, 47 deletions
@@ -87,10 +87,38 @@ process_object(cJSON *json) JSON_GET(json, height); JSON_GET(json, rotation); JSON_GET(json, visible); - printf("{\"%s\",\"%s\",%d,%d,%d,%d,%d,%f,%d},", + printf("{\"%s\",\"%s\",%d,%d,%d,%d,%d,%f,%d,", name->valuestring, type->valuestring, id->valueint, x->valueint, y->valueint, width->valueint, height->valueint, rotation->valuedouble, cJSON_IsTrue(visible)); + + cJSON *properties = cJSON_GetObjectItem(json, "properties"); + if (!cJSON_IsArray(properties)) + printf("0,0"); + else { + printf("(const Tiled2cProperty[]){"); + int size = 0; + cJSON *property; + cJSON_ArrayForEach(property, properties) { + size += 1; + JSON_GET_STRING(property, name); + JSON_GET_STRING(property, type); + printf("{\"%s\",\"%s\",", + name->valuestring, type->valuestring); + + if (type->valuestring[0] == 's') { + JSON_GET_STRING(property, value); + printf("\"%s\"}", value->valuestring); + } + if (type->valuestring[0] == 'o') { + JSON_GET(property, value); + printf("\"%f\"}", value->valuedouble); + } + } + printf("},%d", size); + } + + printf("},"); return 0; } @@ -4,49 +4,49 @@ extern "C" { #endif typedef struct { - double duration; - double tileid; + double duration; + double tileid; } Tiled2cFrame; typedef struct { - unsigned int id; - const char *type; - double probability; - const int numframes; - const Tiled2cFrame *frames; + unsigned int id; + const char *type; + double probability; + const int numframes; + const Tiled2cFrame *frames; } Tiled2cTile; typedef struct { - const char *name; - const char *path; - unsigned int imagewidth; - unsigned int imageheight; - unsigned int tilewidth; - unsigned int tileheight; - unsigned int margin; - unsigned int columns; - unsigned int tilecount; - unsigned int numtiles; - const Tiled2cTile *tiles; + const char *name; + const char *path; + unsigned int imagewidth; + unsigned int imageheight; + unsigned int tilewidth; + unsigned int tileheight; + unsigned int margin; + unsigned int columns; + unsigned int tilecount; + unsigned int numtiles; + const Tiled2cTile *tiles; } Tiled2cSet; typedef struct { - const unsigned int *data; + const unsigned int *data; } Tiled2cTilelayer; typedef struct { - const char *image; - int x; - int y; + const char *image; + int x; + int y; } Tiled2cImagelayer; typedef struct { - const char *name; - unsigned int type; - double opacity; - unsigned int visible; - double parallaxx; - double parallaxy; + const char *name; + unsigned int type; + double opacity; + unsigned int visible; + double parallaxx; + double parallaxy; union { Tiled2cTilelayer tilelayer; Tiled2cImagelayer imagelayer; @@ -54,27 +54,38 @@ typedef struct { } Tiled2cLayer; typedef struct { - const char *name; - const char *type; - unsigned int id; - double x; - double y; - double width; - double height; - double rotation; - unsigned int visible; + const char *name; + const char *type; + union { + const char *valuestring; + double valuenumber; + }; +} Tiled2cProperty; + +typedef struct { + const char *name; + const char *type; + unsigned int id; + double x; + double y; + double width; + double height; + double rotation; + unsigned int visible; + const Tiled2cProperty *properties; + unsigned int numproperties; } Tiled2cObject; typedef struct { - const char *path; - unsigned int width; - unsigned int height; - unsigned int tilewidth; - unsigned int tileheight; - unsigned int numlayers; - const Tiled2cLayer *layers; - const Tiled2cObject *objects; - unsigned int numobjects; + const char *path; + unsigned int width; + unsigned int height; + unsigned int tilewidth; + unsigned int tileheight; + unsigned int numlayers; + const Tiled2cLayer *layers; + const Tiled2cObject *objects; + unsigned int numobjects; } Tiled2cMap; #ifdef __cplusplus |