CleverRaven/Cataclysm-DDA — pull request #2874 by yobbobanana (2013-09-06 10:30:10+00:00)
Title: Complete overhaul of JSON loading system [CR]

The main change is that objects are loaded from json files according to their "type".

So in stead of having all objects of a certain type in one file, a single file can contain objects of many types, and they will all be instantiated and filed correctly.

Currently I've only converted materials.json, bionics.json and professions.json to using this system, but this should be enough to demonstrate what I'm aiming for.

The new JSON loader class is Jsin in json.cpp (with the intention of creating a Jsout class as well at some point).

Usage can be seen in material_type::load_material(), profession::load_profession() and load_bionic().

The way it works, is that the Jsin class is instantiated with an ifstream to a .json file. It maintains a position in the file, and provides methods to read bools, ints, strings etc directly from the underlying stream. As each object is reached, it's scanned for a "type" member, and then dispatched to the relevant constructor. That constructor then loops over the object members, reading them into the internal data structure according to their names.

Note that it's intended mainly for loading data/raw/*.json at the moment, I haven't thought much about gamestate serialization yet.

The main benefits so far are:
* data may be loaded dynamically from any .json file, not just one data type per file. This should lead to super-easy packaging of user modifications. For example someone could add a new profession, some new items, and a new vehicle, and distribute them in a single .json file, which could be loaded just by dropping it in a special user mod directory.
* intermediate data-structures can be avoided, as values are interpreted directly from the underlying stream.
* the structure is fairly simple, so new functionality can easily be added.
* no external libraries / licenses.

Most of it can still be changed. Any comments are welcome.