From 03b817a354913240b3bccd4148c9acec39933acc Mon Sep 17 00:00:00 2001 From: zlago Date: Mon, 14 Oct 2024 13:24:27 +0200 Subject: add flying enemy --- utl/json2map/main.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'utl/json2map') 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; -- cgit 1.4.1-2-gfad0