acabat amb SDL_Log
This commit is contained in:
340
source/param.cpp
340
source/param.cpp
@@ -9,80 +9,10 @@
|
||||
Param param;
|
||||
|
||||
// Calcula variables a partir de otras variables
|
||||
void precalculateZones()
|
||||
{
|
||||
// playArea
|
||||
param.game.play_area.center_x = param.game.play_area.rect.w / 2;
|
||||
param.game.play_area.first_quarter_x = param.game.play_area.rect.w / 4;
|
||||
param.game.play_area.third_quarter_x = param.game.play_area.rect.w / 4 * 3;
|
||||
param.game.play_area.center_y = param.game.play_area.rect.h / 2;
|
||||
param.game.play_area.first_quarter_y = param.game.play_area.rect.h / 4;
|
||||
param.game.play_area.third_quarter_y = param.game.play_area.rect.h / 4 * 3;
|
||||
|
||||
// gameArea
|
||||
param.game.game_area.rect = {0, 0, static_cast<float>(param.game.width), static_cast<float>(param.game.height)};
|
||||
param.game.game_area.center_x = param.game.game_area.rect.w / 2;
|
||||
param.game.game_area.first_quarter_x = param.game.game_area.rect.w / 4;
|
||||
param.game.game_area.third_quarter_x = param.game.game_area.rect.w / 4 * 3;
|
||||
param.game.game_area.center_y = param.game.game_area.rect.h / 2;
|
||||
param.game.game_area.first_quarter_y = param.game.game_area.rect.h / 4;
|
||||
param.game.game_area.third_quarter_y = param.game.game_area.rect.h / 4 * 3;
|
||||
}
|
||||
void precalculateZones();
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setParams(const std::string &var, const std::string &value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
auto success = true;
|
||||
|
||||
// GAME
|
||||
if (var == "game.width")
|
||||
{
|
||||
param.game.width = std::stoi(value);
|
||||
}
|
||||
else if (var == "game.height")
|
||||
{
|
||||
param.game.height = std::stoi(value);
|
||||
}
|
||||
else if (var == "game.item_size")
|
||||
{
|
||||
param.game.item_size = std::stoi(value);
|
||||
}
|
||||
else if (var == "game.coffee_machine_w")
|
||||
{
|
||||
param.game.coffee_machine_w = std::stoi(value);
|
||||
}
|
||||
else if (var == "game.coffee_machine_h")
|
||||
{
|
||||
param.game.coffee_machine_h = std::stoi(value);
|
||||
}
|
||||
else if (var == "game.play_area.rect.x")
|
||||
{
|
||||
param.game.play_area.rect.x = std::stoi(value);
|
||||
}
|
||||
else if (var == "game.play_area.rect.y")
|
||||
{
|
||||
param.game.play_area.rect.y = std::stoi(value);
|
||||
}
|
||||
else if (var == "game.play_area.rect.w")
|
||||
{
|
||||
param.game.play_area.rect.w = std::stoi(value);
|
||||
}
|
||||
else if (var == "game.play_area.rect.h")
|
||||
{
|
||||
param.game.play_area.rect.h = std::stoi(value);
|
||||
}
|
||||
else if (var == "game.enter_name_seconds")
|
||||
{
|
||||
param.game.enter_name_seconds = std::stoi(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
bool setParams(const std::string &var, const std::string &value);
|
||||
|
||||
// Establece valores por defecto a las variables
|
||||
void initParam()
|
||||
@@ -149,7 +79,7 @@ void loadParamsFromFile(const std::string &file_path)
|
||||
throw std::runtime_error("No se pudo abrir el archivo: " + file_path);
|
||||
}
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Leyendo archivo: %s", getFileName(file_path).c_str());
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(file_path).c_str());
|
||||
|
||||
std::string line, param1, param2;
|
||||
while (std::getline(file, line))
|
||||
@@ -178,3 +108,267 @@ void loadParamsFromFile(const std::string &file_path)
|
||||
// Realiza cálculos adicionales después de cargar los parámetros
|
||||
precalculateZones();
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
bool setParams(const std::string &var, const std::string &value)
|
||||
{
|
||||
// Indicador de éxito en la asignación
|
||||
auto success = true;
|
||||
|
||||
// GAME
|
||||
if (var == "game.width")
|
||||
{
|
||||
param.game.width = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.height")
|
||||
{
|
||||
param.game.height = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.item_size")
|
||||
{
|
||||
param.game.item_size = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.coffee_machine_w")
|
||||
{
|
||||
param.game.coffee_machine_w = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.coffee_machine_h")
|
||||
{
|
||||
param.game.coffee_machine_h = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.play_area.rect.x")
|
||||
{
|
||||
param.game.play_area.rect.x = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.play_area.rect.y")
|
||||
{
|
||||
param.game.play_area.rect.y = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.play_area.rect.w")
|
||||
{
|
||||
param.game.play_area.rect.w = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.play_area.rect.h")
|
||||
{
|
||||
param.game.play_area.rect.h = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.enter_name_seconds")
|
||||
{
|
||||
param.game.enter_name_seconds = std::stoi(value);
|
||||
}
|
||||
|
||||
// FADE
|
||||
else if (var == "fade.num_squares_width")
|
||||
{
|
||||
param.fade.num_squares_width = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "fade.num_squares_height")
|
||||
{
|
||||
param.fade.num_squares_height = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "fade.random_squares_delay")
|
||||
{
|
||||
param.fade.random_squares_delay = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "fade.random_squares_mult")
|
||||
{
|
||||
param.fade.random_squares_mult = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "fade.post_duration")
|
||||
{
|
||||
param.fade.post_duration = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "fade.venetian_size")
|
||||
{
|
||||
param.fade.venetian_size = std::stoi(value);
|
||||
}
|
||||
|
||||
// SCOREBOARD
|
||||
else if (var == "scoreboard.x")
|
||||
{
|
||||
param.scoreboard.x = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.y")
|
||||
{
|
||||
param.scoreboard.y = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.w")
|
||||
{
|
||||
param.scoreboard.w = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.h")
|
||||
{
|
||||
param.scoreboard.h = std::stoi(value);
|
||||
}
|
||||
|
||||
// TITLE
|
||||
else if (var == "title.press_start_position")
|
||||
{
|
||||
param.title.press_start_position = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "title.title_duration")
|
||||
{
|
||||
param.title.title_duration = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "title.arcade_edition_position")
|
||||
{
|
||||
param.title.arcade_edition_position = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "title.title_c_c_position")
|
||||
{
|
||||
param.title.title_c_c_position = std::stoi(value);
|
||||
}
|
||||
|
||||
// BACKGROUND
|
||||
else if (var == "background.attenuate_color.r")
|
||||
{
|
||||
param.background.attenuate_color.r = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "background.attenuate_color.g")
|
||||
{
|
||||
param.background.attenuate_color.g = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "background.attenuate_color.b")
|
||||
{
|
||||
param.background.attenuate_color.b = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "background.attenuate_alpha")
|
||||
{
|
||||
param.background.attenuate_alpha = std::stoi(value);
|
||||
}
|
||||
|
||||
// BALLOON
|
||||
else if (var == "balloon_1.vel")
|
||||
{
|
||||
param.balloon.at(0).vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon_1.grav")
|
||||
{
|
||||
param.balloon.at(0).grav = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon_2.vel")
|
||||
{
|
||||
param.balloon.at(1).vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon_2.grav")
|
||||
{
|
||||
param.balloon.at(1).grav = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon_3.vel")
|
||||
{
|
||||
param.balloon.at(2).vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon_3.grav")
|
||||
{
|
||||
param.balloon.at(2).grav = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon_4.vel")
|
||||
{
|
||||
param.balloon.at(3).vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon_4.grav")
|
||||
{
|
||||
param.balloon.at(3).grav = std::stof(value);
|
||||
}
|
||||
|
||||
// NOTIFICACIONES
|
||||
else if (var == "notification.pos_h")
|
||||
{
|
||||
if (value == "LEFT")
|
||||
{
|
||||
param.notification.pos_h = NotifyPosition::LEFT;
|
||||
}
|
||||
else if (value == "MIDDLE")
|
||||
{
|
||||
param.notification.pos_h = NotifyPosition::MIDDLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
param.notification.pos_h = NotifyPosition::RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "notification.pos_v")
|
||||
{
|
||||
param.notification.pos_v = value == "TOP" ? NotifyPosition::TOP : NotifyPosition::BOTTOM;
|
||||
}
|
||||
|
||||
else if (var == "notification.sound")
|
||||
{
|
||||
param.notification.sound = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "notification.color.r")
|
||||
{
|
||||
param.notification.color.r = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "notification.color.g")
|
||||
{
|
||||
param.notification.color.g = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "notification.color.b")
|
||||
{
|
||||
param.notification.color.b = std::stoi(value);
|
||||
}
|
||||
|
||||
// RESTO
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Calcula variables a partir de otras variables
|
||||
void precalculateZones()
|
||||
{
|
||||
// playArea
|
||||
param.game.play_area.center_x = param.game.play_area.rect.w / 2;
|
||||
param.game.play_area.first_quarter_x = param.game.play_area.rect.w / 4;
|
||||
param.game.play_area.third_quarter_x = param.game.play_area.rect.w / 4 * 3;
|
||||
param.game.play_area.center_y = param.game.play_area.rect.h / 2;
|
||||
param.game.play_area.first_quarter_y = param.game.play_area.rect.h / 4;
|
||||
param.game.play_area.third_quarter_y = param.game.play_area.rect.h / 4 * 3;
|
||||
|
||||
// gameArea
|
||||
param.game.game_area.rect = {0, 0, param.game.width, param.game.height};
|
||||
param.game.game_area.center_x = param.game.game_area.rect.w / 2;
|
||||
param.game.game_area.first_quarter_x = param.game.game_area.rect.w / 4;
|
||||
param.game.game_area.third_quarter_x = param.game.game_area.rect.w / 4 * 3;
|
||||
param.game.game_area.center_y = param.game.game_area.rect.h / 2;
|
||||
param.game.game_area.first_quarter_y = param.game.game_area.rect.h / 4;
|
||||
param.game.game_area.third_quarter_y = param.game.game_area.rect.h / 4 * 3;
|
||||
}
|
||||
Reference in New Issue
Block a user