Exemplo n.º 1
0
/** Read the file with the tips-of-the-day. */
static void read_tips_of_day(config& tips_of_day)
{
	loadscreen::global_loadscreen->disable_increments = true;
	
	tips_of_day.clear();

#ifdef FREE_VERSION
	std::string filename = get_cache_dir() + "/tips_free";
#else
	std::string filename = get_cache_dir() + "/tips";
#endif
	std::string checkFilename = filename + ".cache.dat";
	if (!file_exists(checkFilename))
	{
		try {
#ifdef FREE_VERSION
			scoped_istream stream = preprocess_file(get_wml_location("hardwired/tips_free.cfg"));
#else
			scoped_istream stream = preprocess_file(get_wml_location("hardwired/tips.cfg"));
#endif
			read(tips_of_day, *stream);
		} catch(config::error&) {
	//		ERR_CONFIG << "Could not read data/hardwired/tips.cfg\n";
		}
	
		tips_of_day.saveCache(filename);
	}
	else
	{
		tips_of_day.loadCache(filename);
	}
	
	
	//we shuffle the tips after each initial loading. We only shuffle if
	//the upload_log preference has been set. If it hasn't been set, it's the
	//user's first time playing since this feature has been added, so we'll
	//leave the tips in their default order, which will always contain a tip
	//regarding the upload log first, so the user sees it.
	config::child_itors tips = tips_of_day.child_range("tip");
	if (tips.first != tips.second && preferences::has_upload_log()) {
		std::random_shuffle(tips.first, tips.second);
	}
	
	//Make sure that the upload log preference is set, if it's not already, so
	//that we know next time we've already seen the message about uploads.
	if(!preferences::has_upload_log()) 
	{
		//preferences::set_upload_log(preferences::upload_log());
		preferences::set_upload_log(false);
	}
	loadscreen::global_loadscreen->disable_increments = false;

}
Exemplo n.º 2
0
bool load_language_list()
{
	config cfg;
	try {
		if (game_config::use_bin) {
			wml_config_from_file(game_config::path + "/xwml/" + "language.bin", cfg);
		} else {
			scoped_istream stream = preprocess_file(get_wml_location("hardwired/language.cfg"));
			read(cfg, *stream);

			wml_config_to_file(game_config::path + "/xwml/" + "language.bin", cfg);
		}
	} catch(config::error &) {
		return false;
	}

	known_languages.clear();
	known_languages.push_back(
		language_def("", t_string(N_("System default language"), "wesnoth"), "ltr", "", "A"));

	foreach (const config &lang, cfg.child_range("locale"))
	{
		known_languages.push_back(
			language_def(lang["locale"], lang["name"], lang["dir"],
			             lang["alternates"], lang["sort_name"]));
	}

	return true;
}
Exemplo n.º 3
0
std::string read_map(const std::string& name)
{
	std::string res;
	std::string map_location = get_wml_location("maps/" + name);
	if(!map_location.empty()) {
		res = read_file(map_location);
	}

	if (res.empty()) {
		res = read_file(get_user_data_dir() + "/editor/maps/" + name);
	}

	return res;
}
Exemplo n.º 4
0
bool set_language(const language_def& locale)
{
	strings_.clear();

	std::string locale_lc;
	locale_lc.resize(locale.localename.size());
	std::transform(locale.localename.begin(),locale.localename.end(),locale_lc.begin(),tolower);

	config cfg;

	current_language = locale;
	wesnoth_setlocale(LC_MESSAGES, locale.localename, &locale.alternates);
	wesnoth_setlocale(LC_COLLATE, locale.localename, &locale.alternates);

	// fill string_table (should be moved somwhere else some day)
	try {
		scoped_istream stream = preprocess_file(get_wml_location("hardwired/english.cfg"));
		read(cfg, *stream);
	} catch(config::error& e) {
		std::cerr << "Could not read english.cfg\n";
		throw e;
	}

	config* langp = cfg.child("language");
	if (langp == NULL) {
		std::cerr << "No [language] block found in english.cfg\n";
		return false;
	}

	for(string_map::const_iterator j = langp->values.begin(); j != langp->values.end(); ++j) {
		strings_[j->first] = j->second;
	}
	// end of string_table fill

	// Reset translations for the name of current languages
//	for (language_list::iterator itor = known_languages.begin();
//			itor != known_languages.end(); ++itor) {
//
//		itor->language.reset_translation();
//	}

	return true;
}
/** Read the file with the tips-of-the-day. */
void read_tips_of_day(config& tips_of_day)
{
	tips_of_day.clear();
	LOG_CF << "Loading tips of day\n";
	try {
		scoped_istream stream = preprocess_file(get_wml_location("hardwired/tips.cfg"));
		read(tips_of_day, *stream);
	} catch(config::error&) {
		ERR_CF << "Could not read data/hardwired/tips.cfg\n";
	}

	//We shuffle the tips after each initial loading.
	config::const_child_itors itors = tips_of_day.child_range("tip");
	if (itors.first != itors.second ) {
		std::vector<config> tips(itors.first, itors.second);
		std::random_shuffle(tips.begin(), tips.end());
		tips_of_day.clear();
		foreach (const config &tip, tips) {
			tips_of_day.add_child("tip", tip);
		}
Exemplo n.º 6
0
bool load_language_list()
{
	config cfg;
	try {
		scoped_istream stream = preprocess_file(get_wml_location("hardwired/language.cfg"));
		read(cfg, *stream);
	} catch(config::error &) {
		return false;
	}

	known_languages.clear();
	known_languages.push_back(
		language_def("", t_string(N_("System default language"), "wesnoth"), "ltr", "", "A"));

	BOOST_FOREACH(const config &lang, cfg.child_range("locale"))
	{
		known_languages.push_back(
			language_def(lang["locale"], lang["name"], lang["dir"],
			             lang["alternates"], lang["sort_name"]));
	}

	return true;
}
Exemplo n.º 7
0
bool load_language_list()
{
	config cfg;
	try {
		scoped_istream stream = preprocess_file(get_wml_location("hardwired/language.cfg"));
		read(cfg, *stream);
	} catch(config::error &) {
		return false;
	}

	known_languages.clear();
	known_languages.push_back(
		language_def("", "System default language", "ltr", "", "A"));

	config::const_child_itors langs = cfg.child_range("locale");
	for(;langs.first != langs.second; ++langs.first) {
		known_languages.push_back(
			language_def((**langs.first)["locale"], (**langs.first)["name"], (**langs.first)["dir"],
				(**langs.first)["alternates"], (**langs.first)["sort_name"]));
	}

	return true;
}
Exemplo n.º 8
0
bool set_language(const language_def& locale)
{
	strings_.clear();

	std::string locale_lc;
	locale_lc.resize(locale.localename.size());
	std::transform(locale.localename.begin(),locale.localename.end(),locale_lc.begin(),tolower);

	config cfg;

	current_language = locale;
	wesnoth_setlocale(LC_COLLATE, locale.localename, &locale.alternates);
	wesnoth_setlocale(LC_TIME, locale.localename, &locale.alternates);
	wesnoth_setlocale(LC_MESSAGES, locale.localename, &locale.alternates);

	// fill string_table (should be moved somwhere else some day)
	try {
		scoped_istream stream = preprocess_file(get_wml_location("hardwired/english.cfg"));
		read(cfg, *stream);
	} catch(config::error& e) {
		std::cerr << "Could not read english.cfg\n";
		throw e;
	}

	config &langp = cfg.child("language");
	if (!langp) {
		std::cerr << "No [language] block found in english.cfg\n";
		return false;
	}

	foreach (const config::attribute &j, langp.attribute_range()) {
		strings_[j.first] = j.second;
	}
	// end of string_table fill

	return true;
}
Exemplo n.º 9
0
/** Read the file with the tips-of-the-day. */
void read_tips_of_day(config& tips_of_day)
{
	tips_of_day.clear();
	LOG_CF << "Loading tips of day\n";
	try {
		scoped_istream stream = preprocess_file(get_wml_location("hardwired/tips.cfg"));
		read(tips_of_day, *stream);
	} catch(config::error&) {
		ERR_CF << "Could not read data/hardwired/tips.cfg\n";
	}

	//we shuffle the tips after each initial loading. We only shuffle if
	//the upload_log preference has been set. If it hasn't been set, it's the
	//user's first time playing since this feature has been added, so we'll
	//leave the tips in their default order, which will always contain a tip
	//regarding the upload log first, so the user sees it.
	config::const_child_itors itors = tips_of_day.child_range("tip");
	if (itors.first != itors.second && preferences::has_upload_log()) {
		std::vector<config> tips(itors.first, itors.second);
		std::random_shuffle(tips.begin(), tips.end());
		tips_of_day.clear();
		foreach (const config &tip, tips) {
			tips_of_day.add_child("tip", tip);
		}
Exemplo n.º 10
0
void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload,
	game_classification const* classification)
{
	// Make sure that 'debug mode' symbol is set
	// if command line parameter is selected
	// also if we're in multiplayer and actual debug mode is disabled.
	game_config::scoped_preproc_define debug_mode("DEBUG_MODE",
	    game_config::debug || game_config::mp_debug);

	// Game_config already holds requested config in memory.
	if(!game_config_.empty() &&
		(force_reload == NO_FORCE_RELOAD)
		&& old_defines_map_ == cache_.get_preproc_map()) {
		return;
	}

	loadscreen::global_loadscreen_manager loadscreen_manager(disp_.video());
	cursor::setter cur(cursor::WAIT);

	// The loadscreen will erase the titlescreen.
	// NOTE: even without loadscreen, needed after MP lobby.
	try {
		// Read all game configs.
		// First we should load data/,
		// then handle terrains so that they are last loaded from data/.
		// 2nd everything in userdata.
		loadscreen::start_stage("verify cache");
		data_tree_checksum();
		loadscreen::start_stage("create cache");

		// Start transaction so macros are shared.
		game_config::config_cache_transaction main_transaction;

		// Load the selected core
		cache_.get_config(get_wml_location(preferences::wml_tree_root()), game_config_);
		// Load the mainline core definitions to make sure switching back is always possible.
		config default_core_cfg;
		cache_.get_config(game_config::path + "/data/cores.cfg", default_core_cfg);
		game_config_.append(default_core_cfg);

		main_transaction.lock();

		// Put the gfx rules aside so that we can prepend the add-on
		// rules to them.
		config core_terrain_rules;
		core_terrain_rules.splice_children(game_config_, "terrain_graphics");

		load_addons_cfg();

		// If multiplayer campaign is being loaded, [scenario] tags should
		// become [multiplayer] tags and campaign's id should be added to them
		// to allow to recognize which scenarios belongs to a loaded campaign.
		if (classification != NULL) {
			if (classification->campaign_type == game_classification::MULTIPLAYER &&
				!classification->campaign_define.empty()) {

				const config& campaign = game_config().find_child("campaign",
					"define", classification->campaign_define);
				const std::string& campaign_id = campaign["id"];
				const bool require_campaign =
					campaign["require_campaign"].to_bool(true);

				const config::const_child_itors &ci =
					game_config().child_range("scenario");
				std::vector<config> scenarios(ci.first, ci.second);

				game_config_.clear_children("scenario");

				BOOST_FOREACH(config& cfg, scenarios) {
					cfg["campaign_id"] = campaign_id;
					cfg["require_scenario"] = require_campaign;
					game_config_.add_child(lexical_cast<std::string>(game_classification::MULTIPLAYER), cfg);
				}
			}
		}

		// Extract the Lua scripts at toplevel.
		extract_preload_scripts(game_config_);
		game_config_.clear_children("lua");

		// Put the gfx rules back to game config.
		game_config_.splice_children(core_terrain_rules, "terrain_graphics");

		set_multiplayer_hashes();
		set_color_info();
		set_unit_data();

		terrain_builder::set_terrain_rules_cfg(game_config());
		::init_strings(game_config());
		theme::set_known_themes(&game_config());
	} catch(game::error& e) {