diff --git a/conf/e2/config.json b/conf/e2/config.json index 863a64c0a..beb582a97 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -1,11 +1,30 @@ { "include": [ - "keywords.json", - "calendar.json", - "prefixes.json", - "e2/terrains.json", - "e2/rules.xml", - "e2/locales.xml" + "config://keywords.json", + "config://calendar.json", + "config://prefixes.json", + "config://e2/terrains.json", + "config://e2/locales.xml", + "config://e2/rules.xml", + "rules://core/ships.xml", + "rules://core/spoils.xml", + "rules://core/common/buildings.xml", + "rules://core/common/items.xml", + "rules://core/common/resources.xml", + "rules://core/common/luxuries.xml", + "rules://core/common/herbs.xml", + "rules://core/common/potions.xml", + "rules://core/common/armor.xml", + "rules://core/common/weapons.xml", + "rules://eressea/races.xml", + "rules://eressea/artrewards.xml", + "rules://eressea/buildings.xml", + "rules://eressea/familiars.xml", + "rules://eressea/buildings.xml", + "rules://eressea/equipment.xml", + "rules://eressea/items.xml", + "rules://eressea/spells.xml", + "rules://adamantium.xml" ], "disabled": [ "jsreport" diff --git a/conf/e2/rules.xml b/conf/e2/rules.xml index 22ff8109f..9e40910e0 100644 --- a/conf/e2/rules.xml +++ b/conf/e2/rules.xml @@ -1,24 +1,6 @@ - + - - - - - - - - - - - - - - - - - - diff --git a/res/core/common/items.xml b/res/core/common/items.xml index 564e9fafd..d04b6a252 100644 --- a/res/core/common/items.xml +++ b/res/core/common/items.xml @@ -1,4 +1,5 @@ + @@ -133,3 +134,4 @@ + diff --git a/scripts/eressea/xmlconf.lua b/scripts/eressea/xmlconf.lua index 1b70b0ccd..756d3c18a 100644 --- a/scripts/eressea/xmlconf.lua +++ b/scripts/eressea/xmlconf.lua @@ -1,11 +1,10 @@ -local confdir = 'conf/' -if config.install then - confdir = config.install .. '/' .. confdir -end +local rules = 'conf' + if config.rules then - local rules = config.rules .. '/' - assert(0 == eressea.config.read(rules .. 'config.json', confdir), "could not read JSON data") + rules = rules .. '/' .. config.rules + assert(0 == eressea.config.read(rules .. '/config.json', config.install), "could not read JSON data") -- assert(0 == read_xml(confdir .. rules .. 'rules.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") -- assert(0 == read_xml(confdir .. rules .. 'locales.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") end + eressea.game.reset() diff --git a/src/jsonconf.c b/src/jsonconf.c index 15cc563b6..56ff2e675 100644 --- a/src/jsonconf.c +++ b/src/jsonconf.c @@ -887,16 +887,32 @@ static void json_races(cJSON *json) { const char * json_relpath; -static void include_json(const char *filename) { +static const char * uri_to_file(const char * uri, char *name, size_t size) { + const char *pos, *path = json_relpath; + + pos = strstr(uri, "://"); + if (pos) { + size_t slen = pos - uri; + /* identify scheme */ + if (strncmp(uri, "config", slen) == 0) { + path = path_join(path, "conf", name, size); + } + else if (strncmp(uri, "rules", slen) == 0) { + path = path_join(path, "res", name, size); + } + if (path) { + return path_join(path, pos + 3, name, size); + } + } + return uri; +} + +static void include_json(const char *uri) { FILE *F; - if (json_relpath) { - char name[PATH_MAX]; - path_join(json_relpath, filename, name, sizeof(name)); - F = fopen(name, "r"); - } - else { - F = fopen(filename, "r"); - } + char name[PATH_MAX]; + const char *filename = uri_to_file(uri, name, sizeof(name)); + + F = fopen(filename, "r"); if (F) { long pos; fseek(F, 0, SEEK_END); @@ -917,21 +933,20 @@ static void include_json(const char *filename) { cJSON_Delete(config); } else { - log_error("invalid JSON, could not parse %s", filename); + log_error("could not parse JSON from %s", uri); } } fclose(F); } } -static void include_xml(const char *filename) { +static void include_xml(const char *uri) { char name[PATH_MAX]; - - if (json_relpath) { - path_join(json_relpath, filename, name, sizeof(name)); - filename = name; + const char *filename = uri_to_file(uri, name, sizeof(name)); + int err = read_xml(filename, NULL); + if (err != 0) { + log_error("could not parse XML from %s", uri); } - read_xml(filename, NULL); } static void json_include(cJSON *json) { @@ -941,12 +956,13 @@ static void json_include(cJSON *json) { return; } for (child = json->child; child; child = child->next) { - const char * filename = child->valuestring; - if (strstr(filename, ".xml") != NULL) { - include_xml(filename); + const char *uri = child->valuestring; + + if (strstr(uri, ".xml") != NULL) { + include_xml(uri); } else { - include_json(filename); + include_json(uri); } } }