diff options
author | zlago | 2024-10-14 13:24:27 +0200 |
---|---|---|
committer | zlago | 2024-10-14 13:37:38 +0200 |
commit | 03b817a354913240b3bccd4148c9acec39933acc (patch) | |
tree | d5672dd0af00b0510ab40fcdebc1f7c7d0f7e688 /utl | |
parent | aa441c86b8dc92180968bde492649fe769a63706 (diff) |
add flying enemy
Diffstat (limited to 'utl')
-rw-r--r-- | utl/json2map/main.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/utl/json2map/main.c b/utl/json2map/main.c index 9ffa9b9..beb8909 100644 --- a/utl/json2map/main.c +++ b/utl/json2map/main.c @@ -382,7 +382,7 @@ int main(int argc, char **argv) { //printf("%s:", property->valuestring); char const *const *default_props = (char const *const[]) {"x", "y", "width", "height", NULL}; - if (cJSON_IsTrue(cJSON_GetObjectItemCaseSensitive(object, "point"))) { + if (cJSON_IsTrue(cJSON_GetObjectItemCaseSensitive(object, "point")) || cJSON_GetObjectItemCaseSensitive(object, "polygon") || cJSON_GetObjectItemCaseSensitive(object, "polyline")) { default_props = (char const *const[]) {"x", "y", NULL}; } for (int i = 0; default_props[i] != NULL; i++) { @@ -407,6 +407,53 @@ int main(int argc, char **argv) { return 1; } } + cJSON const *path = cJSON_GetObjectItemCaseSensitive(object, "polygon"); + if (path) { + fputs("polygon ", stdout); + cJSON const *node; + struct blob nodes = blob_new(); + blob_append(&nodes, "path", strlen("path") + 1); + cJSON_ArrayForEach(node, path) { + char buf[64]; + sprintf(buf, "%i,%i ", cJSON_GetObjectItemCaseSensitive(node, "x")->valueint, + cJSON_GetObjectItemCaseSensitive(node, "y")->valueint); + blob_append(&nodes, buf, strlen(buf)); + } + blob_append(&entity, nodes.data, nodes.size - 1); + blob_append(&entity, &(char) {0}, 1); + fwrite(nodes.data, 1, nodes.size - 1, stdout); + blob_free(&nodes); + putchar('\n'); + } + path = cJSON_GetObjectItemCaseSensitive(object, "polyline"); + if (path) { + //fputs("polyline ", stdout); + char **node_strings = malloc(cJSON_GetArraySize(path) * sizeof (char *)); + int node_strings_index = 0; + cJSON const *node; + struct blob nodes = blob_new(); + blob_append(&nodes, "path", strlen("path") + 1); + cJSON_ArrayForEach(node, path) { + char buf[64]; + sprintf(buf, "%i,%i ", cJSON_GetObjectItemCaseSensitive(node, "x")->valueint, + cJSON_GetObjectItemCaseSensitive(node, "y")->valueint); + blob_append(&nodes, buf, strlen(buf)); + node_strings[node_strings_index++] = strdup(buf); + } + free(node_strings[--node_strings_index]); + while (node_strings_index > 1) { + node_strings_index--; + blob_append(&nodes, node_strings[node_strings_index], strlen(node_strings[node_strings_index])); + free(node_strings[node_strings_index]); + } + free(node_strings[--node_strings_index]); + free(node_strings); + blob_append(&entity, nodes.data, nodes.size - 1); + blob_append(&entity, &(char) {0}, 1); + //fwrite(nodes.data, 1, nodes.size - 1, stdout); + blob_free(&nodes); + //putchar('\n'); + } cJSON_ArrayForEach(property, cJSON_GetObjectItemCaseSensitive(object, "properties")) { char const *const name = cJSON_GetObjectItemCaseSensitive(property, "name")->valuestring; char const *const type = cJSON_GetObjectItemCaseSensitive(property, "type")->valuestring; |