forked from github/server
json export for planes. untested. old tests broken. WIP
This commit is contained in:
parent
52e64ac418
commit
a986640ef6
3 changed files with 17 additions and 3 deletions
2
cutest
2
cutest
|
@ -1 +1 @@
|
||||||
Subproject commit 0b718dde0939afdd1f424f5030fc1621d38ba6db
|
Subproject commit d83cec09a52835274ab8ed4849de16fb8658982a
|
16
src/json.c
16
src/json.c
|
@ -4,6 +4,7 @@
|
||||||
#include "json.h"
|
#include "json.h"
|
||||||
|
|
||||||
#include <kernel/types.h>
|
#include <kernel/types.h>
|
||||||
|
#include <kernel/plane.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
#include <kernel/terrain.h>
|
#include <kernel/terrain.h>
|
||||||
|
@ -58,10 +59,23 @@ int json_export(stream * out, unsigned int flags) {
|
||||||
cJSON *json, *root = cJSON_CreateObject();
|
cJSON *json, *root = cJSON_CreateObject();
|
||||||
assert(out && out->api);
|
assert(out && out->api);
|
||||||
if (regions && (flags & EXPORT_REGIONS)) {
|
if (regions && (flags & EXPORT_REGIONS)) {
|
||||||
|
char id[32];
|
||||||
region * r;
|
region * r;
|
||||||
|
plane * p;
|
||||||
|
cJSON_AddItemToObject(root, "planes", json = cJSON_CreateObject());
|
||||||
|
for (p=planes;p;p=p->next) {
|
||||||
|
cJSON *data;
|
||||||
|
_snprintf(id, sizeof(id), "%u", p->id);
|
||||||
|
cJSON_AddItemToObject(json, id, data = cJSON_CreateObject());
|
||||||
|
cJSON_AddNumberToObject(data, "x", p->minx);
|
||||||
|
cJSON_AddNumberToObject(data, "y", p->miny);
|
||||||
|
cJSON_AddNumberToObject(data, "width", p->maxx-p->minx);
|
||||||
|
cJSON_AddNumberToObject(data, "height", p->maxy-p->miny);
|
||||||
|
cJSON_AddStringToObject(data, "name", p->name);
|
||||||
|
}
|
||||||
|
|
||||||
cJSON_AddItemToObject(root, "regions", json = cJSON_CreateObject());
|
cJSON_AddItemToObject(root, "regions", json = cJSON_CreateObject());
|
||||||
for (r = regions; r; r = r->next) {
|
for (r = regions; r; r = r->next) {
|
||||||
char id[32];
|
|
||||||
cJSON *data;
|
cJSON *data;
|
||||||
_snprintf(id, sizeof(id), "%u", r->uid);
|
_snprintf(id, sizeof(id), "%u", r->uid);
|
||||||
cJSON_AddItemToObject(json, id, data = cJSON_CreateObject());
|
cJSON_AddItemToObject(json, id, data = cJSON_CreateObject());
|
||||||
|
|
|
@ -2355,7 +2355,7 @@ static int parse_main(xmlDocPtr doc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (k == MAXKEYWORDS) {
|
if (k == MAXKEYWORDS) {
|
||||||
log_error("trying to disable unknown comand %s\n", (const char *)propName);
|
log_error("trying to disable unknown command %s\n", (const char *)propName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xmlFree(propName);
|
xmlFree(propName);
|
||||||
|
|
Loading…
Reference in a new issue