summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-12-09 22:02:48 +0100
committerkdx <kikoodx@paranoici.org>2023-12-09 22:02:48 +0100
commitebde0a200e1db431170452fcadd247771d1f2664 (patch)
tree73a104fbe1e4df775df8b48dfbabbdb66772f566
parent6e52997d0db19c557677adb8f5694e29437d027f (diff)
downloadtiled2c-ebde0a200e1db431170452fcadd247771d1f2664.tar.gz
layer class
-rw-r--r--src/main.c12
-rw-r--r--tiled2c.h1
2 files changed, 12 insertions, 1 deletions
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;