void load_keyboard_settings( std::map<char, action_id> &keymap, std::string &keymap_file_loaded_from, std::set<action_id> &unbound_keymap ) { const auto parser = [&]( std::istream & fin ) { parse_keymap( fin, keymap, unbound_keymap ); }; if( read_from_file_optional( FILENAMES["keymap"], parser ) ) { keymap_file_loaded_from = FILENAMES["keymap"]; } else if( read_from_file_optional( FILENAMES["legacy_keymap"], parser ) ) { keymap_file_loaded_from = FILENAMES["legacy_keymap"]; } }
bool read_from_file_optional_json( const std::string &path, const std::function<void( JsonIn & )> &reader ) { return read_from_file_optional( path, [&reader]( std::istream & fin ) { JsonIn jsin( fin ); reader( jsin ); } ); }
void zone_manager::load_zones() { std::string savefile = world_generator->active_world->world_path + "/" + base64_encode( g->u.name ) + ".zones.json"; read_from_file_optional( savefile, [&]( std::istream & fin ) { JsonIn jsin( fin ); deserialize( jsin ); } ); cache_data(); }
void zone_manager::load_zones() { std::string savefile = g->get_player_base_save_path() + ".zones.json"; read_from_file_optional( savefile, [&]( std::istream & fin ) { JsonIn jsin( fin ); deserialize( jsin ); } ); revert_vzones(); added_vzones.clear(); changed_vzones.clear(); removed_vzones.clear(); cache_data(); }
//helper function for those have problem inputing certain characters. std::string get_input_string_from_file( std::string fname ) { std::string ret; read_from_file_optional( fname, [&ret]( std::istream & fin ) { getline( fin, ret ); //remove utf8 bmm if( !ret.empty() && ( unsigned char )ret[0] == 0xef ) { ret.erase( 0, 3 ); } while( !ret.empty() && ( ret[ret.size() - 1] == '\r' || ret[ret.size() - 1] == '\n' ) ) { ret.erase( ret.size() - 1, 1 ); } } ); return ret; }
std::vector<std::string> main_menu::load_file( const std::string &path, const std::string &alt_text ) const { std::vector<std::string> result; read_from_file_optional( path, [&result]( std::istream & fin ) { std::string line; while( std::getline( fin, line ) ) { if( !line.empty() && line[0] == '#' ) { continue; } result.push_back( line ); } } ); if( result.empty() ) { result.push_back( alt_text ); } return result; }
bool read_from_file_optional( const std::string &path, JsonDeserializer &reader ) { return read_from_file_optional( path, [&reader]( JsonIn & jsin ) { reader.deserialize( jsin ); } ); }
void main_menu::init_strings() { // ASCII Art mmenu_title = load_file( PATH_INFO::find_translated_file( "titledir", ".title", "title" ), _( "Cataclysm: Dark Days Ahead" ) ); // MOTD mmenu_motd = load_file( PATH_INFO::find_translated_file( "motddir", ".motd", "motd" ), _( "No message today." ) ); // Credits mmenu_credits.clear(); std::vector<std::string> buffer; read_from_file_optional( PATH_INFO::find_translated_file( "creditsdir", ".credits", "credits" ), [&buffer, this]( std::istream & stream ) { std::string line; while( std::getline( stream, line ) ) { if( line[0] == '#' ) { continue; } else { buffer.push_back( line ); } if( buffer.size() > 14 || line.empty() ) { std::ostringstream ss; for( std::vector<std::string>::iterator it = buffer.begin(); it != buffer.end(); ++it ) { ss << *it << std::endl; } mmenu_credits.push_back( ss.str() ); buffer.clear(); } } } ); if( !buffer.empty() ) { std::ostringstream ss; for( std::vector<std::string>::iterator it = buffer.begin(); it != buffer.end(); ++it ) { ss << *it << std::endl; } mmenu_credits.push_back( ss.str() ); } if( mmenu_credits.empty() ) { mmenu_credits.push_back( _( "No credits information found." ) ); } // fill menu with translated menu items vMenuItems.clear(); vMenuItems.push_back( pgettext( "Main Menu", "<M|m>OTD" ) ); vMenuItems.push_back( pgettext( "Main Menu", "<N|n>ew Game" ) ); vMenuItems.push_back( pgettext( "Main Menu", "Lo<a|A>d" ) ); vMenuItems.push_back( pgettext( "Main Menu", "<W|w>orld" ) ); vMenuItems.push_back( pgettext( "Main Menu", "<S|s>pecial" ) ); vMenuItems.push_back( pgettext( "Main Menu", "Se<t|T>tings" ) ); vMenuItems.push_back( pgettext( "Main Menu", "H<e|E|?>lp" ) ); vMenuItems.push_back( pgettext( "Main Menu", "<C|c>redits" ) ); vMenuItems.push_back( pgettext( "Main Menu", "<Q|q>uit" ) ); // determine hotkeys from translated menu item text vMenuHotkeys.clear(); for( const std::string &item : vMenuItems ) { vMenuHotkeys.push_back( get_hotkeys( item ) ); } vWorldSubItems.clear(); vWorldSubItems.push_back( pgettext( "Main Menu|World", "<D|d>elete World" ) ); vWorldSubItems.push_back( pgettext( "Main Menu|World", "<R|r>eset World" ) ); vWorldSubItems.push_back( pgettext( "Main Menu|World", "<S|s>how World Mods" ) ); vWorldHotkeys.clear(); for( const std::string &item : vWorldSubItems ) { vWorldHotkeys.push_back( get_hotkeys( item ) ); } vSettingsSubItems.clear(); vSettingsSubItems.push_back( pgettext( "Main Menu|Settings", "<O|o>ptions" ) ); vSettingsSubItems.push_back( pgettext( "Main Menu|Settings", "K<e|E>ybindings" ) ); vSettingsSubItems.push_back( pgettext( "Main Menu|Settings", "<A|a>utopickup" ) ); vSettingsSubItems.push_back( pgettext( "Main Menu|Settings", "<S|s>afemode" ) ); vSettingsSubItems.push_back( pgettext( "Main Menu|Settings", "<C|c>olors" ) ); vSettingsHotkeys.clear(); for( auto item : vSettingsSubItems ) { vSettingsHotkeys.push_back( get_hotkeys( item ) ); } }