const harvest_id &harvest_list::load( JsonObject &jo, const std::string &src, const std::string &force_id ) { harvest_list ret; if( jo.has_string( "id" ) ) { ret.id_ = harvest_id( jo.get_string( "id" ) ); } else if( !force_id.empty() ) { ret.id_ = harvest_id( force_id ); } else { jo.throw_error( "id was not specified for harvest" ); } if( jo.has_string( "message" ) ) { ret.message_ = jo.get_string( "message" ); } JsonArray jo_entries = jo.get_array( "entries" ); while( jo_entries.has_more() ) { JsonObject current_entry = jo_entries.next_object(); ret.entries_.push_back( harvest_entry::load( current_entry, src ) ); } auto &new_entry = harvest_all[ ret.id_ ]; new_entry = ret; return new_entry.id(); }
void map_data_common_t::load( JsonObject &jo, const std::string &src ) { if( jo.has_member( "examine_action" ) ) { examine = iexamine_function_from_string( jo.get_string( "examine_action" ) ); } else { examine = iexamine_function_from_string( "none" ); } if( jo.has_array( "harvest_by_season" ) ) { JsonArray jsarr = jo.get_array( "harvest_by_season" ); while( jsarr.has_more() ) { JsonObject harvest_jo = jsarr.next_object(); auto season_strings = harvest_jo.get_tags( "seasons" ); std::set<season_type> seasons; std::transform( season_strings.begin(), season_strings.end(), std::inserter( seasons, seasons.begin() ), []( const std::string & data ) { return io::string_to_enum<season_type>( data ); } ); harvest_id hl; if( harvest_jo.has_array( "entries" ) ) { // @todo: A better inline name - can't use id or name here because it's not set yet size_t num = harvest_list::all().size() + 1; hl = harvest_list::load( harvest_jo, src, string_format( "harvest_inline_%d", static_cast<int>( num ) ) ); } else if( harvest_jo.has_string( "id" ) ) { hl = harvest_id( harvest_jo.get_string( "id" ) ); } else { jo.throw_error( "Each harvest entry must specify either \"entries\" or \"id\"", "harvest_by_season" ); } for( season_type s : seasons ) { harvest_by_season[ s ] = hl; } } } optional( jo, false, "description", description, translated_string_reader ); }