json_item_substitution::trait_requirements json_item_substitution::trait_requirements::load( JsonArray &arr ) { trait_requirements ret; arr.read_next( ret.present ); if( arr.test_array() ) { arr.read_next( ret.absent ); } return ret; }
/* * load player from ginormous json blob */ void player::deserialize(JsonIn &jsin) { JsonObject data = jsin.get_object(); JsonArray parray; json_load_common_variables( data ); std::string prof_ident="(null)"; if ( data.read("profession",prof_ident) && profession::exists(prof_ident) ) { prof = profession::prof(prof_ident); } else { debugmsg("Tried to use non-existent profession '%s'", prof_ident.c_str()); } data.read("activity",activity); data.read("backlog",backlog); data.read("driving_recoil",driving_recoil); data.read("in_vehicle",in_vehicle); data.read("controlling_vehicle",controlling_vehicle); data.read("grab_point", grab_point); std::string grab_typestr="OBJECT_NONE"; if( grab_point.x != 0 || grab_point.y != 0 ) { grab_typestr = "OBJECT_VEHICLE"; data.read( "grab_type", grab_typestr); } if ( obj_type_id.find(grab_typestr) != obj_type_id.end() ) { grab_type = (object_type)obj_type_id[grab_typestr]; } data.read( "blocks_left", num_blocks); data.read( "focus_pool", focus_pool); data.read( "style_selected", style_selected ); data.read( "health", health ); data.read( "mutations", my_mutations ); set_highest_cat_level(); drench_mut_calc(); parray = data.get_array("temp_cur"); if ( parray.size() == num_bp ) { for(int i=0; i < num_bp; i++) { temp_cur[i]=parray.get_int(i); } } else { debugmsg("Error, incompatible temp_cur in save file %s",parray.str().c_str()); } parray = data.get_array("temp_conv"); if ( parray.size() == num_bp ) { for(int i=0; i < num_bp; i++) { temp_conv[i]=parray.get_int(i); } } else { debugmsg("Error, incompatible temp_conv in save file %s",parray.str().c_str()); } parray = data.get_array("frostbite_timer"); if ( parray.size() == num_bp ) { for(int i=0; i < num_bp; i++) { frostbite_timer[i]=parray.get_int(i); } } else { debugmsg("Error, incompatible frostbite_timer in save file %s",parray.str().c_str()); } parray = data.get_array("learned_recipes"); if ( !parray.empty() ) { learned_recipes.clear(); std::string pstr=""; while ( parray.has_more() ) { if ( parray.read_next(pstr) ) { learned_recipes[ pstr ] = recipe_by_name( pstr ); } } } data.read("morale", morale); data.read( "active_mission", active_mission ); data.read( "active_missions", active_missions ); data.read( "failed_missions", failed_missions ); data.read( "completed_missions", completed_missions ); stats & pstats = *lifetime_stats(); data.read("player_stats",pstats); inv.clear(); if ( data.has_member("inv") ) { JsonIn* jip = data.get_raw("inv"); inv.json_load_items( *jip ); } if ( data.has_member("invcache") ) { JsonIn* jip = data.get_raw("invcache"); inv.json_load_invcache( *jip ); } worn.clear(); data.read("worn", worn); weapon.contents.clear(); data.read("weapon", weapon); }