示例#1
0
void Profile::loadSettings()
{
	INI ini;
	if (! ini.load(this->fileSettings))
		return;

// Small macro to avoid unnecessary typing.
//
// To get something from the ini file we send the
// text (to identify some value) and the default
// value in case it doesn't exist.
//
// For the last one I send the variable itself,
// so we fallback to the default values.
#define INI_GET(var, text) \
	{ \
		var = ini.get(text, var); \
	}

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

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

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

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

	// Game

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

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

	INI_GET(settings.game.random_algorithm, "game:random_algorithm");

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

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

	// Getting input keys
	std::string tmp;

	INI_GET(tmp, "input:left");
	InputManager::bind("left", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input:right");
	InputManager::bind("right", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input:down");
	InputManager::bind("down", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input:drop");
	InputManager::bind("drop", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input:rotate_clockwise");
	InputManager::bind("rotate_clockwise", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input:rotate_counterclockwise");
	InputManager::bind("rotate_counterclockwise", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input:pause");
	InputManager::bind("pause", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input:help");
	InputManager::bind("help", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input:hold");
	InputManager::bind("hold", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input:quit");
	InputManager::bind("quit", InputManager::stringToKey(tmp));

	// 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_GET(settings.theme.piece_has_colors, "theme:piece_colors");
	INI_GET(settings.theme.ghost_has_colors, "theme:ghost_colors");
	INI_GET(settings.theme.show_pivot_block, "theme:show_pivot_block");
	INI_GET(settings.theme.lock_piece_color, "theme:lock_piece_colors");

// 	std::string tmp;

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

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

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

// 	INI_GET_THEME(settings.theme.piece,     "piece:block");
// 	INI_GET_THEME(settings.theme.ghost,     "ghost:block");
// 	INI_GET_THEME(settings.theme.locked,    "locked:block");
// 	INI_GET_THEME(settings.theme.invisible, "invisible:block");
// 	INI_GET_THEME(settings.theme.piece_S,   "piece_S:block");
// 	INI_GET_THEME(settings.theme.piece_Z,   "piece_Z:block");
// 	INI_GET_THEME(settings.theme.piece_O,   "piece_O:block");
// 	INI_GET_THEME(settings.theme.piece_I,   "piece_I:block");
// 	INI_GET_THEME(settings.theme.piece_L,   "piece_L:block");
// 	INI_GET_THEME(settings.theme.piece_J,   "piece_J:block");
// 	INI_GET_THEME(settings.theme.piece_T,   "piece_T:block");
}
示例#2
0
void Profile::loadSettings()
{
	INI::Parser* ini = NULL;

	try {
		ini = new INI::Parser(this->fileSettings);
	}
	catch(std::runtime_error& e)
	{
		// File doesn't exist (or we couldn't access it)
		// Either way, ignore it silently
		SAFE_DELETE(ini);
		return;
	}

	std::string buffer;

// Small macro to avoid unnecessary typing.
//
// To get something from the ini file we send the
// text (to identify some value) and the default
// value in case it doesn't exist.
//
// For the last one I send the variable itself,
// so we fallback to the default values.
#define INI_GET(var, out, in)                    \
	{                                            \
		buffer = (* ini)(out)[in];               \
		if (! buffer.empty())                    \
		{                                        \
			Utils::String::convert(buffer, var); \
		}                                        \
	}

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

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

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

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

	// Special case, getting a string
	INI_GET(settings.screen.animation_menu, "screen", "animation_menu");
	INI_GET(settings.screen.animation_game, "screen", "animation_game");

	// Game
	INI_GET(settings.game.next_pieces, "game", "next_pieces");
	INI_GET(settings.game.has_ghost,   "game", "ghost");
	INI_GET(settings.game.can_hold,    "game", "hold");

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

	// Getting input keys
	std::string tmp;

	INI_GET(tmp, "input", "left");
	InputManager::bind("left", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "right");
	InputManager::bind("right", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "down");
	InputManager::bind("down", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "drop");
	InputManager::bind("drop", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "rotate_clockwise");
	InputManager::bind("rotate_clockwise", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "rotate_counterclockwise");
	InputManager::bind("rotate_counterclockwise", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "rotate_180");
	InputManager::bind("rotate_180", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "pause");
	InputManager::bind("pause", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "help");
	InputManager::bind("help", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "hold");
	InputManager::bind("hold", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "quit");
	InputManager::bind("quit", InputManager::stringToKey(tmp));

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

	try {
		ini = new INI::Parser(this->fileTheme);
	}
	catch(std::runtime_error& e)
	{
		// File doesn't exist (or we couldn't access it)
		// Either way, ignore it silently
		SAFE_DELETE(ini);
		return;
	}

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

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

// 	std::string tmp;

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

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

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

// 	INI_GET_THEME(settings.theme.piece,     "piece:block");
// 	INI_GET_THEME(settings.theme.ghost,     "ghost:block");
// 	INI_GET_THEME(settings.theme.locked,    "locked:block");
// 	INI_GET_THEME(settings.theme.invisible, "invisible:block");
// 	INI_GET_THEME(settings.theme.piece_S,   "piece_S:block");
// 	INI_GET_THEME(settings.theme.piece_Z,   "piece_Z:block");
// 	INI_GET_THEME(settings.theme.piece_O,   "piece_O:block");
// 	INI_GET_THEME(settings.theme.piece_I,   "piece_I:block");
// 	INI_GET_THEME(settings.theme.piece_L,   "piece_L:block");
// 	INI_GET_THEME(settings.theme.piece_J,   "piece_J:block");
// 	INI_GET_THEME(settings.theme.piece_T,   "piece_T:block");

	SAFE_DELETE(ini);
}
示例#3
0
void Globals::loadFile()
{
	// Now, back on track
	if (! Utils::File::exists(Globals::Config::file))
		return;

	INI::Parser* ini = NULL;

	try {
		ini = new INI::Parser(Globals::Config::file);
	}
	catch(std::runtime_error& e)
	{
		// File doesn't exist (or we couldn't access it)
		// Either way, ignore it silently
		SAFE_DELETE(ini);
		return;
	}

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

// Small macro to avoid unnecessary typing.
//
// To get something from the ini file we send the
// text (to identify some value) and the default
// value in case it doesn't exist.
//
// For the last one I send the variable itself,
// so we fallback to the default values.
#define INI_GET(var, out, in)                    \
	{                                            \
		buffer = (* ini)(out)[in];               \
		if (! buffer.empty())                    \
		{                                        \
			Utils::String::convert(buffer, var); \
		}                                        \
	}

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

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

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

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

	// unsigned ints are the exception - their overloading
	// is ambiguous... I should consider removing them altogether
	buffer = (* ini)("game")["starting_speed"];
	if (! buffer.empty())
	{
		int starting_speed = Globals::Game::starting_speed;
		Utils::String::convert(buffer, starting_speed);
		Globals::Game::starting_speed = starting_speed;
	}

	// Special Cases

	// Getting input keys
	std::string tmp;

	INI_GET(tmp, "input", "left");
	InputManager::bind("left", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "right");
	InputManager::bind("right", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "up");
	InputManager::bind("up", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "down");
	InputManager::bind("down", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "pause");
	InputManager::bind("pause", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "help");
	InputManager::bind("help", InputManager::stringToKey(tmp));

	INI_GET(tmp, "input", "quit");
	InputManager::bind("quit", InputManager::stringToKey(tmp));

	// Board Size
	int board_size = 2;
	INI_GET(board_size, "game", "board_size");
	Globals::Game::board_size = Globals::Game::intToBoardSize(board_size);

	SAFE_DELETE(ini);
}