summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-04-09 20:38:03 +0200
committerkdx <kikoodx@paranoici.org>2023-04-09 20:38:16 +0200
commit992970eab07bc7da9a3393bc444a919cd701e10b (patch)
tree61cf6cfeaa3bab96c72126ee8746d655e8a5df91
parent13b7580a46e8e6ae3e94aa60b60a8d3813a5db37 (diff)
downloadtiled2c-992970eab07bc7da9a3393bc444a919cd701e10b.tar.gz
facultative tiles
-rw-r--r--src/main.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index b4bedb8..d0db66e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -157,7 +157,11 @@ process_tileset(const char *word, cJSON *json)
{
JSON_GET_STRING(json, name);
JSON_GET_STRING(json, image);
- JSON_GET_ARRAY(json, tiles);
+ cJSON *tiles = cJSON_GetObjectItem(json, "tiles");
+ if (tiles != NULL && !cJSON_IsArray(tiles)) {
+ fprintf(stderr, "tiles is no array\n");
+ return -1;
+ }
JSON_GET(json, imagewidth);
JSON_GET(json, imageheight);
JSON_GET(json, tilewidth);
@@ -172,12 +176,15 @@ process_tileset(const char *word, cJSON *json)
word, name->valuestring, image->valuestring,
imagewidth->valueint, imageheight->valueint,
tilewidth->valueint, tileheight->valueint, margin->valueint,
- columns->valueint, tilecount->valueint, tiles_size);
+ columns->valueint, tilecount->valueint,
+ (tiles != NULL) ? cJSON_GetArraySize(tiles) : 0);
- cJSON *tile;
- cJSON_ArrayForEach(tile, tiles)
- if (process_tile(tile))
- return -1;
+ if (tiles != NULL) {
+ cJSON *tile;
+ cJSON_ArrayForEach(tile, tiles)
+ if (process_tile(tile))
+ return -1;
+ }
printf("}};\n");
return 0;
}