// copypasta: init.cpp void load_object(JsonObject &jo) { std::string type = jo.get_string("type"); if ( ! jo.has_string("type") ) { std::stringstream err; err << jo.line_number() << ": "; err << "JSON object has no type"; throw err.str(); } }
void DynamicDataLoader::load_object(JsonObject &jo) { std::string type = jo.get_string("type"); t_type_function_map::iterator it = type_function_map.find(type); if (it == type_function_map.end()) { std::stringstream err; err << jo.line_number() << ": "; err << "unrecognized JSON object, type: \"" << type << "\""; throw err.str(); } (*it->second)(jo); }
void load_object(JsonObject &jo) { std::string type = jo.get_string("type"); if (type_function_map.find(type) != type_function_map.end()) { (*type_function_map[type])(jo); } else { std::stringstream err; err << jo.line_number() << ": "; err << "unrecognized JSON object, type: \"" << type << "\""; throw err.str(); } }
void load_object(JsonObject &jo) { std::string type = jo.get_string("type"); if (type == "material") { material_type::load_material(jo);} else if (type == "bionic") { load_bionic(jo); } else if (type == "profession") { profession::load_profession(jo); } else if (type == "skill") { Skill::load_skill(jo); } else if (type == "dream") { load_dream(jo); } else if (type == "mutation") { load_mutation(jo); } else if (type == "snippet") { SNIPPET.load_snippet(jo); } else if (type == "item_group") { item_controller->load_item_group(jo); } else if (type == "recipe_category") { load_recipe_category(jo); } else if (type == "recipe") { load_recipe(jo); } else { std::stringstream err; err << jo.line_number() << ": "; err << "unrecognized JSON object, type: \"" << type << "\""; throw err.str(); } }
void load_artifacts_from_ifstream(std::ifstream &f) { // read and create artifacts from json array in artifacts.gsav JsonIn artifact_json(f); artifact_json.start_array(); while (!artifact_json.end_array()) { JsonObject jo = artifact_json.get_object(); std::string type = jo.get_string("type"); std::string id = jo.get_string("id"); if (type == "artifact_tool") { it_artifact_tool *art = new it_artifact_tool(jo); item_controller->add_item_type( art ); } else if (type == "artifact_armor") { it_artifact_armor *art = new it_artifact_armor(jo); item_controller->add_item_type( art ); } else { throw jo.line_number() + ": unrecognized artifact type."; } } }
// Load an item group from JSON void Item_factory::load_item_group(JsonObject &jsobj) { Item_tag group_id = jsobj.get_string("id"); Item_group *current_group = new Item_group(group_id); m_template_groups[group_id] = current_group; JsonArray items = jsobj.get_array("items"); while (items.has_more()) { JsonArray pair = items.next_array(); current_group->add_entry(pair.get_string(0), pair.get_int(1)); } JsonArray groups = jsobj.get_array("groups"); while (groups.has_more()) { JsonArray pair = groups.next_array(); std::string name = pair.get_string(0); int frequency = pair.get_int(1); // we had better have loaded it already! if (m_template_groups.find(name) == m_template_groups.end()) { throw jsobj.line_number() + ": unrecognized group name: " + name; } current_group->add_group(m_template_groups[name], frequency); } }
void load_artifacts_from_ifstream(std::ifstream &f, itypemap &itypes) { // delete current artefact ids artifact_itype_ids.clear(); // read and create artifacts from json array in artifacts.gsav JsonIn artifact_json(f); artifact_json.start_array(); while (!artifact_json.end_array()) { JsonObject jo = artifact_json.get_object(); std::string type = jo.get_string("type"); std::string id = jo.get_string("id"); if (type == "artifact_tool") { it_artifact_tool *art = new it_artifact_tool(jo); itypes[id] = art; artifact_itype_ids.push_back(id); } else if (type == "artifact_armor") { it_artifact_armor *art = new it_artifact_armor(jo); itypes[id] = art; artifact_itype_ids.push_back(id); } else { throw jo.line_number() + ": unrecognized artifact type."; } } }