From 40d7d236ace2eff91f67bf4308666d78cdc6be45 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 6 Mar 2014 08:05:26 -0800 Subject: [PATCH] export to a stream can write a dict of simple regions now. --- src/export.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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); } }