From ebde0a200e1db431170452fcadd247771d1f2664 Mon Sep 17 00:00:00 2001 From: kdx Date: Sat, 9 Dec 2023 22:02:48 +0100 Subject: layer class --- src/main.c | 12 +++++++++++- tiled2c.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 176af47..95edb33 100644 --- a/src/main.c +++ b/src/main.c @@ -15,6 +15,12 @@ return -1; \ } +#define JSON_GET_OPT_STRING(j, s) cJSON *const s = cJSON_GetObjectItem(j, #s); \ + if (s != NULL && !cJSON_IsString(s)) { \ + fprintf(stderr, #s " is no string\n"); \ + return -1; \ + } + #define JSON_GET_ARRAY(j, s) JSON_GET(j, s); \ if (!cJSON_IsArray(s)) { \ fprintf(stderr, #s " is no array\n"); \ @@ -28,13 +34,17 @@ process_layer(cJSON *json) { JSON_GET_STRING(json, type); JSON_GET_STRING(json, name); + JSON_GET_OPT_STRING(json, class); JSON_GET(json, opacity); JSON_GET(json, visible); cJSON *const parallaxx = cJSON_GetObjectItem(json, "parallaxx"); cJSON *const parallaxy = cJSON_GetObjectItem(json, "parallaxy"); - printf("{\"%s\",'%c',%f,%d,%f,%f,", + printf("{\"%s\",%c%s%c,'%c',%f,%d,%f,%f,", name->valuestring, + class ? '"' : 'N', + class ? class->valuestring : "UL", + class ? '"' : 'L', type->valuestring[0], opacity->valuedouble, cJSON_IsTrue(visible), diff --git a/tiled2c.h b/tiled2c.h index a35971b..446af8e 100644 --- a/tiled2c.h +++ b/tiled2c.h @@ -51,6 +51,7 @@ typedef struct { typedef struct { const char *name; + const char *class; unsigned int type; double opacity; unsigned int visible; -- cgit v1.2.3