summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2024-01-23 15:32:14 +0100
committerkdx <kikoodx@paranoici.org>2024-01-23 15:32:14 +0100
commit988c12415ac8b1f99c8138c9c136602a2cd54f54 (patch)
tree85912aa5b81502ca2b21cc566163add3188dbdea
parent7e27aed0f603c26a853ef5d2c630505a79318227 (diff)
downloadtiled2c-988c12415ac8b1f99c8138c9c136602a2cd54f54.tar.gz
internal tile objectgroup
-rw-r--r--src/main.c20
-rw-r--r--tiled2c.h32
2 files changed, 34 insertions, 18 deletions
diff --git a/src/main.c b/src/main.c
index a35ff7e..c5accb1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;
}
diff --git a/tiled2c.h b/tiled2c.h
index 9ad79a8..e6fb692 100644
--- a/tiled2c.h
+++ b/tiled2c.h
@@ -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;