diff --git a/src/export.c b/src/export.c index 0c8213f11..83d3e42c5 100644 --- a/src/export.c +++ b/src/export.c @@ -2,9 +2,10 @@ #include #include #include +#include #include "cJSON.h" -void export_json(const char *filename) { +void export_json(stream * out) { region * r; cJSON *json, *root = cJSON_CreateObject(); cJSON_AddItemToObject(root, "regions", json = cJSON_CreateObject()); @@ -15,6 +16,18 @@ void export_json(const char *filename) { cJSON_AddItemToObject(json, id, data = cJSON_CreateObject()); cJSON_AddNumberToObject(data, "x", r->x); cJSON_AddNumberToObject(data, "y", r->y); - cJSON_AddStringToObject(data, "terrain", r->terrain->_name); + cJSON_AddStringToObject(data, "type", r->terrain->_name); + } + if (out) { + char *tok, *output; + output = cJSON_Print(json); + tok = strtok(output, "\n\r"); + while (tok) { + if (tok[0]) { + out->api->writeln(out->handle, tok); + } + tok = strtok(NULL, "\n\r"); + } + free(output); } }