NatePixTable::NatePixTable(int id, uint8_t color) { Resource rsrc("sprites", "json", id); String data(utf8::decode(rsrc.data())); Json json; if (!string_to_json(data, json)) { throw Exception("invalid sprite json"); } PixTableVisitor::State state; json.accept(PixTableVisitor(state, id, color, _frames)); }
FilePrefsDriver::FilePrefsDriver() { try { String path(format("{0}/config.json", dirs().root)); MappedFile file(path); Json json; String data(utf8::decode(file.data())); if (!string_to_json(data, json)) { return; } set_from<int>(json, "sound", "volume", _current, &Preferences::volume); set_from<bool>(json, "sound", "speech", _current, &Preferences::speech_on); set_from<bool>(json, "sound", "idle music", _current, &Preferences::play_idle_music); set_from<bool>(json, "sound", "game music", _current, &Preferences::play_music_in_game); for (auto i : range<size_t>(KEY_COUNT)) { set_from<int>(json, "keys", kKeyNames[i], _current, &Preferences::keys, i); } } catch (Exception& e) { // pass } }
json_object * value_to_json(struct svalue *sp) { static int depth = 0; json_object *ret = NULL; if (++depth > MAX_DEPTH) { depth = 0; error("Too deep recursion"); } switch(sp->type) { case T_NUMBER: ret = int_to_json(sp); break; case T_STRING: ret = string_to_json(sp); break; case T_POINTER: ret = array_to_json(sp); break; case T_MAPPING: ret = mapping_to_json(sp); break; case T_FLOAT: ret = float_to_json(sp); break; default: error("Unsupported data type in val2json"); break; } depth--; return ret; }