Exemple #1
0
void Globals::saveFile()
{
	// Even if the file doesn't exist, we'll create it.
	INI ini;
	if (! ini.load(Globals::Config::file))
		ini.create();

// Other macro to avoid typing, similar to the one
// at loadFile()
#define INI_SET(text, var) \
	{ \
		ini.set(text, Utils::String::toString(var)); \
	}


	INI_SET("screen:center_horizontal", Globals::Screen::center_horizontally);
	INI_SET("screen:center_vertical",   Globals::Screen::center_vertically);

	INI_SET("screen:borders",       Globals::Screen::show_borders);
	INI_SET("screen:fancy_borders", Globals::Screen::fancy_borders);
	INI_SET("screen:outer_border",  Globals::Screen::outer_border);

	INI_SET("game:starting_level",   Globals::Game::starting_level);
	INI_SET("game:random_walls",     Globals::Game::random_walls);
	INI_SET("game:fruits_at_once",   Globals::Game::fruits_at_once);
	INI_SET("game:teleport",         Globals::Game::teleport);

	// Special Cases

	// Input Keys
	std::string key;

	key = InputManager::keyToString(InputManager::getBind("left"));
	INI_SET("input:left", key);

	key = InputManager::keyToString(InputManager::getBind("right"));
	INI_SET("input:right", key);

	key = InputManager::keyToString(InputManager::getBind("up"));
	INI_SET("input:up", key);

	key = InputManager::keyToString(InputManager::getBind("down"));
	INI_SET("input:down", key);

	key = InputManager::keyToString(InputManager::getBind("pause"));
	INI_SET("input:pause", key);

	key = InputManager::keyToString(InputManager::getBind("help"));
	INI_SET("input:help", key);

	key = InputManager::keyToString(InputManager::getBind("quit"));
	INI_SET("input:quit", key);

	// Board size
	int board_size = Globals::Game::boardSizeToInt(Globals::Game::board_size);
	INI_SET("game:board_size", board_size);

	ini.save(Globals::Config::file);
}
Exemple #2
0
void Profile::saveSettings()
{
	INI ini;
	if (! ini.load(this->fileSettings))
		return;

#define INI_SET(text, var) \
	{ \
		ini.set(text, Utils::String::toString(var)); \
	}

	INI_SET("screen:center_horizontal", settings.screen.center_horizontally);
	INI_SET("screen:center_vertical",   settings.screen.center_vertically);

	INI_SET("screen:borders",       settings.screen.show_borders);
	INI_SET("screen:fancy_borders", settings.screen.fancy_borders);
	INI_SET("screen:outer_border",  settings.screen.outer_border);

	INI_SET("screen:colors", settings.screen.use_colors);

	INI_SET("screen:statistics", settings.screen.show_statistics);

	// Game

	INI_SET("game:next_pieces",    settings.game.next_pieces);
	INI_SET("game:initial_noise",  settings.game.initial_noise);
	INI_SET("game:starting_level", settings.game.starting_level);

	INI_SET("game:ghost", settings.game.has_ghost);
	INI_SET("game:hold",  settings.game.can_hold);

	ini.set("game:random_algorithm", settings.game.random_algorithm);

	INI_SET("game:game_over_animation", settings.game.has_game_over_animation);
	INI_SET("game:line_clear_delay",    settings.game.line_clear_delay);

	INI_SET("game:slide_left",  settings.game.slide_left);
	INI_SET("game:slide_right", settings.game.slide_right);
	INI_SET("game:invisible",   settings.game.invisible);

	// Input Keys
	std::string key;

	key = InputManager::keyToString(InputManager::getBind("left"));
	INI_SET("input:left", key);

	key = InputManager::keyToString(InputManager::getBind("right"));
	INI_SET("input:right", key);

	key = InputManager::keyToString(InputManager::getBind("down"));
	INI_SET("input:down", key);

	key = InputManager::keyToString(InputManager::getBind("drop"));
	INI_SET("input:drop", key);

	key = InputManager::keyToString(InputManager::getBind("rotate_clockwise"));
	INI_SET("input:rotate_clockwise", key);

	key = InputManager::keyToString(InputManager::getBind("rotate_counterclockwise"));
	INI_SET("input:rotate_counterclockwise", key);

	key = InputManager::keyToString(InputManager::getBind("pause"));
	INI_SET("input:pause", key);

	key = InputManager::keyToString(InputManager::getBind("help"));
	INI_SET("input:help", key);

	key = InputManager::keyToString(InputManager::getBind("hold"));
	INI_SET("input:hold", key);

	key = InputManager::keyToString(InputManager::getBind("quit"));
	INI_SET("input:quit", key);

	ini.save(this->fileSettings);

	// Now, to the Theme file!

	ini.free();
	if (! ini.load(this->fileTheme))
		return;

	// FIXME: For now we're not dealing with colors,
	//        only with block appearances!

	INI_SET("theme:piece_colors", settings.theme.piece_has_colors);
	INI_SET("theme:ghost_colors", settings.theme.ghost_has_colors);
	INI_SET("theme:show_pivot_block", settings.theme.show_pivot_block);
	INI_SET("theme:lock_piece_colors", settings.theme.lock_piece_color);

	ini.save(this->fileTheme);

// 	std::string tmp;

// #define INI_SET_THEME(var, text)
// 	{
// 		tmp = ini.get(text, var.appearance);
// 		var.appearance[0] = tmp[0];
// 		var.appearance[1] = tmp[1];
// 	}

// 	INI_SET_THEME(settings.theme.clear_line, "clear_line:block");

// 	INI_SET_THEME(settings.theme.piece_colorless, "piece_colorless:block");

// 	INI_SET_THEME(settings.theme.piece,     "piece:block");
// 	INI_SET_THEME(settings.theme.ghost,     "ghost:block");
// 	INI_SET_THEME(settings.theme.locked,    "locked:block");
// 	INI_SET_THEME(settings.theme.invisible, "invisible:block");
// 	INI_SET_THEME(settings.theme.piece_S,   "piece_S:block");
// 	INI_SET_THEME(settings.theme.piece_Z,   "piece_Z:block");
// 	INI_SET_THEME(settings.theme.piece_O,   "piece_O:block");
// 	INI_SET_THEME(settings.theme.piece_I,   "piece_I:block");
// 	INI_SET_THEME(settings.theme.piece_L,   "piece_L:block");
// 	INI_SET_THEME(settings.theme.piece_J,   "piece_J:block");
// 	INI_SET_THEME(settings.theme.piece_T,   "piece_T:block");
}
Exemple #3
0
void Profile::saveSettings()
{
	// Even if the file doesn't exist, we'll create it.
	INI::Parser* ini;

	try
	{
		ini = new INI::Parser(this->fileSettings);
	}
	catch(std::runtime_error& e)
	{
		ini = new INI::Parser();
		ini->create();
	}

	std::string buffer;

// Other macro to avoid typing, similar to the one
// at loadFile()
#define INI_SET(out, in, var)	               \
	{                                          \
		buffer = Utils::String::toString(var); \
		ini->top().addGroup(out);              \
		(* ini)(out).addKey(in, buffer);       \
	}

	INI_SET("screen", "center_horizontal", settings.screen.center_horizontally);
	INI_SET("screen", "center_vertical",   settings.screen.center_vertically);

	INI_SET("screen", "borders",       settings.screen.show_borders);
	INI_SET("screen", "fancy_borders", settings.screen.fancy_borders);
	INI_SET("screen", "outer_border",  settings.screen.outer_border);

	INI_SET("screen", "colors", settings.screen.use_colors);

	INI_SET("screen", "statistics", settings.screen.show_statistics);

	INI_SET("screen", "animation_menu",  settings.screen.animation_menu);
	INI_SET("screen", "animation_game",  settings.screen.animation_game);

	// Game

	INI_SET("game", "next_pieces", settings.game.next_pieces);
	INI_SET("game", "ghost",       settings.game.has_ghost);
	INI_SET("game", "hold",        settings.game.can_hold);

	INI_SET("game", "game_over_animation", settings.game.has_game_over_animation);
	INI_SET("game", "line_clear_delay",    settings.game.line_clear_delay);

	// Input Keys
	std::string key;

	key = InputManager::keyToString(InputManager::getBind("left"));
	INI_SET("input", "left", key);

	key = InputManager::keyToString(InputManager::getBind("right"));
	INI_SET("input", "right", key);

	key = InputManager::keyToString(InputManager::getBind("down"));
	INI_SET("input", "down", key);

	key = InputManager::keyToString(InputManager::getBind("drop"));
	INI_SET("input", "drop", key);

	key = InputManager::keyToString(InputManager::getBind("rotate_clockwise"));
	INI_SET("input", "rotate_clockwise", key);

	key = InputManager::keyToString(InputManager::getBind("rotate_counterclockwise"));
	INI_SET("input", "rotate_counterclockwise", key);

	key = InputManager::keyToString(InputManager::getBind("rotate_180"));
	INI_SET("input", "rotate_180", key);

	key = InputManager::keyToString(InputManager::getBind("pause"));
	INI_SET("input", "pause", key);

	key = InputManager::keyToString(InputManager::getBind("help"));
	INI_SET("input", "help", key);

	key = InputManager::keyToString(InputManager::getBind("hold"));
	INI_SET("input", "hold", key);

	key = InputManager::keyToString(InputManager::getBind("quit"));
	INI_SET("input", "quit", key);

	try
	{
		ini->saveAs(this->fileSettings);
	}
	catch(std::runtime_error& e)
	{
		// Couldn't save the file...
		// ... do nothing
	}

	// Now, to the Theme file!
	SAFE_DELETE(ini);

	try {
		ini = new INI::Parser(this->fileTheme);
	}
	catch(std::runtime_error& e)
	{
		ini = new INI::Parser();
		ini->create();
	}

	// FIXME: For now we're not dealing with colors,
	//        only with block appearances!

	INI_SET("theme", "piece_colors", settings.theme.piece_has_colors);
	INI_SET("theme", "ghost_colors", settings.theme.ghost_has_colors);
	INI_SET("theme", "show_pivot_block", settings.theme.show_pivot_block);
	INI_SET("theme", "lock_piece_colors", settings.theme.lock_piece_color);

	try
	{
		ini->saveAs(this->fileTheme);
	}
	catch(std::runtime_error& e)
	{
		// Couldn't save the file...
		// ... do nothing
	}

// 	std::string tmp;

// #define INI_SET_THEME(var, text)
// 	{
// 		tmp = ini.get(text, var.appearance);
// 		var.appearance[0] = tmp[0];
// 		var.appearance[1] = tmp[1];
// 	}

// 	INI_SET_THEME(settings.theme.clear_line, "clear_line:block");

// 	INI_SET_THEME(settings.theme.piece_colorless, "piece_colorless:block");

// 	INI_SET_THEME(settings.theme.piece,     "piece:block");
// 	INI_SET_THEME(settings.theme.ghost,     "ghost:block");
// 	INI_SET_THEME(settings.theme.locked,    "locked:block");
// 	INI_SET_THEME(settings.theme.invisible, "invisible:block");
// 	INI_SET_THEME(settings.theme.piece_S,   "piece_S:block");
// 	INI_SET_THEME(settings.theme.piece_Z,   "piece_Z:block");
// 	INI_SET_THEME(settings.theme.piece_O,   "piece_O:block");
// 	INI_SET_THEME(settings.theme.piece_I,   "piece_I:block");
// 	INI_SET_THEME(settings.theme.piece_L,   "piece_L:block");
// 	INI_SET_THEME(settings.theme.piece_J,   "piece_J:block");
// 	INI_SET_THEME(settings.theme.piece_T,   "piece_T:block");
	SAFE_DELETE(ini);
}
Exemple #4
0
void Globals::saveFile()
{
	// Even if the file doesn't exist, we'll create it.
	INI::Parser* ini;

	try
	{
		ini = new INI::Parser(Globals::Config::file);
	}
	catch(std::runtime_error& e)
	{
		ini = new INI::Parser();
		ini->create();
	}

	// Will be used on this macro below
	std::string buffer;

// Other macro to avoid typing, similar to the one
// at loadFile()
#define INI_SET(out, in, var)	               \
	{                                          \
		buffer = Utils::String::toString(var); \
		ini->top().addGroup(out);              \
		(* ini)(out).addKey(in, buffer);       \
	}

	INI_SET("screen", "center_horizontal", EngineGlobals::Screen::center_horizontally);
	INI_SET("screen", "center_vertical",   EngineGlobals::Screen::center_vertically);

	INI_SET("screen", "borders",       EngineGlobals::Screen::show_borders);
	INI_SET("screen", "fancy_borders", EngineGlobals::Screen::fancy_borders);
	INI_SET("screen", "outer_border",  EngineGlobals::Screen::outer_border);

	INI_SET("game", "random_walls",     Globals::Game::random_walls);
	INI_SET("game", "fruits_at_once",   Globals::Game::fruits_at_once);
	INI_SET("game", "teleport",         Globals::Game::teleport);

	INI_SET("game", "board_scroll_delay", Globals::Game::board_scroll_delay);

	INI_SET("game", "board_scroll_up",    Globals::Game::board_scroll_up);
	INI_SET("game", "board_scroll_down",  Globals::Game::board_scroll_down);
	INI_SET("game", "board_scroll_left",  Globals::Game::board_scroll_left);
	INI_SET("game", "board_scroll_right", Globals::Game::board_scroll_right);

	// unsigned ints are the exception - their overloading
	// is ambiguous... I should consider removing them altogether
	int starting_speed = Globals::Game::starting_speed;
	buffer = Utils::String::toString(starting_speed);
	ini->top().addGroup("game");
	(* ini)("game").addKey("starting_speed", buffer);

	// Special Cases

	// Input Keys
	std::string key;

	key = InputManager::keyToString(InputManager::getBind("left"));
	INI_SET("input", "left", key);

	key = InputManager::keyToString(InputManager::getBind("right"));
	INI_SET("input", "right", key);

	key = InputManager::keyToString(InputManager::getBind("up"));
	INI_SET("input", "up", key);

	key = InputManager::keyToString(InputManager::getBind("down"));
	INI_SET("input", "down", key);

	key = InputManager::keyToString(InputManager::getBind("pause"));
	INI_SET("input", "pause", key);

	key = InputManager::keyToString(InputManager::getBind("help"));
	INI_SET("input", "help", key);

	key = InputManager::keyToString(InputManager::getBind("quit"));
	INI_SET("input", "quit", key);

	// Board size
	int board_size = Globals::Game::boardSizeToInt(Globals::Game::board_size);
	INI_SET("game", "board_size", board_size);

	try
	{
		ini->saveAs(Globals::Config::file);
	}
	catch(std::runtime_error& e)
	{
		// Couldn't save the file...
		// ... do nothing
	}
	SAFE_DELETE(ini);
}