canvi de pc (toquejant Options)
This commit is contained in:
@@ -8,51 +8,56 @@
|
||||
#include "lang.h" // Para Code
|
||||
#include "utils.h" // Para boolToString, stringToBool, getFileName
|
||||
|
||||
// Variables
|
||||
Options options;
|
||||
namespace Options
|
||||
{
|
||||
// Vector con las dificultades
|
||||
std::vector<Difficulty> difficulties = {
|
||||
{DifficultyCode::EASY, "Easy"},
|
||||
{DifficultyCode::NORMAL, "Normal"},
|
||||
{DifficultyCode::HARD, "Hard"}};
|
||||
|
||||
// Declaraciones
|
||||
// Declaraciones
|
||||
bool setOptions(const std::string &var, const std::string &value);
|
||||
|
||||
// Inicializa las opciones del programa
|
||||
void initOptions()
|
||||
{
|
||||
options.window.caption = "Coffee Crisis Arcade Edition";
|
||||
options.window.size = 2;
|
||||
window.caption = "Coffee Crisis Arcade Edition";
|
||||
window.size = 2;
|
||||
|
||||
// Opciones de video
|
||||
options.video.fullscreen = false;
|
||||
options.video.scale_mode = SDL_ScaleMode::SDL_SCALEMODE_NEAREST;
|
||||
options.video.v_sync = true;
|
||||
options.video.integer_scale = true;
|
||||
options.video.shaders = false;
|
||||
video.fullscreen = false;
|
||||
video.scale_mode = SDL_ScaleMode::SDL_SCALEMODE_NEAREST;
|
||||
video.v_sync = true;
|
||||
video.integer_scale = true;
|
||||
video.shaders = false;
|
||||
|
||||
// Opciones de audio
|
||||
options.audio.enabled = true;
|
||||
options.audio.volume = 100;
|
||||
options.audio.music.enabled = true;
|
||||
options.audio.music.volume = 100;
|
||||
options.audio.sound.enabled = true;
|
||||
options.audio.sound.volume = 50;
|
||||
audio.enabled = true;
|
||||
audio.volume = 100;
|
||||
audio.music.enabled = true;
|
||||
audio.music.volume = 100;
|
||||
audio.sound.enabled = true;
|
||||
audio.sound.volume = 50;
|
||||
|
||||
// Opciones de juego
|
||||
options.game.difficulty = GameDifficulty::NORMAL;
|
||||
options.game.language = lang::Code::VALENCIAN;
|
||||
options.game.autofire = true;
|
||||
options.game.shutdown_enabled = false;
|
||||
options.game.clearLastHiScoreEntries();
|
||||
game.difficulty = DifficultyCode::NORMAL;
|
||||
game.language = Lang::Code::VALENCIAN;
|
||||
game.autofire = true;
|
||||
game.shutdown_enabled = false;
|
||||
game.clearLastHiScoreEntries();
|
||||
|
||||
// Opciones de control
|
||||
options.controllers.clear();
|
||||
options.controllers.resize(2);
|
||||
options.controllers.at(0).player_id = 1;
|
||||
options.controllers.at(1).player_id = 2;
|
||||
controllers.clear();
|
||||
controllers.resize(2);
|
||||
controllers.at(0).player_id = 1;
|
||||
controllers.at(1).player_id = 2;
|
||||
setKeyboardToPlayer(1);
|
||||
|
||||
// Opciones pendientes
|
||||
options.pending_changes.new_language = options.game.language;
|
||||
options.pending_changes.new_difficulty = options.game.difficulty;
|
||||
options.pending_changes.has_pending_changes = false;
|
||||
pending_changes.new_language = game.language;
|
||||
pending_changes.new_difficulty = game.difficulty;
|
||||
pending_changes.has_pending_changes = false;
|
||||
}
|
||||
|
||||
// Carga el fichero de configuración
|
||||
@@ -98,11 +103,11 @@ bool loadOptionsFile(std::string file_path)
|
||||
}
|
||||
|
||||
// Normaliza los valores
|
||||
if (options.game.language != lang::Code::ENGLISH &&
|
||||
options.game.language != lang::Code::VALENCIAN &&
|
||||
options.game.language != lang::Code::SPANISH)
|
||||
if (game.language != Lang::Code::ENGLISH &&
|
||||
game.language != Lang::Code::VALENCIAN &&
|
||||
game.language != Lang::Code::SPANISH)
|
||||
{
|
||||
options.game.language = lang::Code::ENGLISH;
|
||||
game.language = Lang::Code::ENGLISH;
|
||||
}
|
||||
|
||||
return success;
|
||||
@@ -128,41 +133,41 @@ bool saveOptionsFile(std::string file_path)
|
||||
file << "## video.scale_mode [" << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_NEAREST) << ": nearest, " << static_cast<int>(SDL_ScaleMode::SDL_SCALEMODE_LINEAR) << ": lineal]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "window.zoom=" << options.window.size << "\n";
|
||||
file << "video.fullscreen=" << boolToString(options.video.fullscreen) << "\n";
|
||||
file << "video.scale_mode=" << static_cast<int>(options.video.scale_mode) << "\n";
|
||||
file << "video.v_sync=" << boolToString(options.video.v_sync) << "\n";
|
||||
file << "video.integer_scale=" << boolToString(options.video.integer_scale) << "\n";
|
||||
file << "video.shaders=" << boolToString(options.video.shaders) << "\n";
|
||||
file << "window.zoom=" << window.size << "\n";
|
||||
file << "video.fullscreen=" << boolToString(video.fullscreen) << "\n";
|
||||
file << "video.scale_mode=" << static_cast<int>(video.scale_mode) << "\n";
|
||||
file << "video.v_sync=" << boolToString(video.v_sync) << "\n";
|
||||
file << "video.integer_scale=" << boolToString(video.integer_scale) << "\n";
|
||||
file << "video.shaders=" << boolToString(video.shaders) << "\n";
|
||||
|
||||
// Opciones de audio
|
||||
file << "\n\n## AUDIO\n";
|
||||
file << "## volume [0 .. 100]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "audio.enabled=" << boolToString(options.audio.enabled) << "\n";
|
||||
file << "audio.volume=" << options.audio.volume << "\n";
|
||||
file << "audio.music.enabled=" << boolToString(options.audio.music.enabled) << "\n";
|
||||
file << "audio.music.volume=" << options.audio.music.volume << "\n";
|
||||
file << "audio.sound.enabled=" << boolToString(options.audio.sound.enabled) << "\n";
|
||||
file << "audio.sound.volume=" << options.audio.sound.volume << "\n";
|
||||
file << "audio.enabled=" << boolToString(audio.enabled) << "\n";
|
||||
file << "audio.volume=" << audio.volume << "\n";
|
||||
file << "audio.music.enabled=" << boolToString(audio.music.enabled) << "\n";
|
||||
file << "audio.music.volume=" << audio.music.volume << "\n";
|
||||
file << "audio.sound.enabled=" << boolToString(audio.sound.enabled) << "\n";
|
||||
file << "audio.sound.volume=" << audio.sound.volume << "\n";
|
||||
|
||||
// Opciones del juego
|
||||
file << "\n\n## GAME\n";
|
||||
file << "## game.language [0: spanish, 1: valencian, 2: english]\n";
|
||||
file << "## game.difficulty [" << static_cast<int>(GameDifficulty::EASY) << ": easy, " << static_cast<int>(GameDifficulty::NORMAL) << ": normal, " << static_cast<int>(GameDifficulty::HARD) << ": hard]\n";
|
||||
file << "## game.difficulty [" << static_cast<int>(DifficultyCode::EASY) << ": easy, " << static_cast<int>(DifficultyCode::NORMAL) << ": normal, " << static_cast<int>(DifficultyCode::HARD) << ": hard]\n";
|
||||
file << "\n";
|
||||
|
||||
file << "game.language=" << static_cast<int>(options.game.language) << "\n";
|
||||
file << "game.difficulty=" << static_cast<int>(options.game.difficulty) << "\n";
|
||||
file << "game.autofire=" << boolToString(options.game.autofire) << "\n";
|
||||
file << "game.shutdown_enabled=" << boolToString(options.game.shutdown_enabled) << "\n";
|
||||
file << "game.language=" << static_cast<int>(game.language) << "\n";
|
||||
file << "game.difficulty=" << static_cast<int>(game.difficulty) << "\n";
|
||||
file << "game.autofire=" << boolToString(game.autofire) << "\n";
|
||||
file << "game.shutdown_enabled=" << boolToString(game.shutdown_enabled) << "\n";
|
||||
|
||||
// Opciones de mandos
|
||||
file << "\n\n## CONTROLLERS\n";
|
||||
|
||||
int controller_index = 0;
|
||||
for (const auto &controller : options.controllers)
|
||||
for (const auto &controller : controllers)
|
||||
{
|
||||
file << "\n";
|
||||
file << "controller." << controller_index << ".name=" << controller.name << "\n";
|
||||
@@ -193,139 +198,139 @@ bool setOptions(const std::string &var, const std::string &value)
|
||||
// Opciones de video
|
||||
if (var == "video.fullscreen")
|
||||
{
|
||||
options.video.fullscreen = stringToBool(value);
|
||||
video.fullscreen = stringToBool(value);
|
||||
}
|
||||
else if (var == "window.zoom")
|
||||
{
|
||||
options.window.size = std::stoi(value);
|
||||
window.size = std::stoi(value);
|
||||
}
|
||||
else if (var == "video.scale_mode")
|
||||
{
|
||||
options.video.scale_mode = static_cast<SDL_ScaleMode>(std::stoi(value));
|
||||
video.scale_mode = static_cast<SDL_ScaleMode>(std::stoi(value));
|
||||
}
|
||||
else if (var == "video.shaders")
|
||||
{
|
||||
options.video.shaders = stringToBool(value);
|
||||
video.shaders = stringToBool(value);
|
||||
}
|
||||
else if (var == "video.integer_scale")
|
||||
{
|
||||
options.video.integer_scale = stringToBool(value);
|
||||
video.integer_scale = stringToBool(value);
|
||||
}
|
||||
else if (var == "video.v_sync")
|
||||
{
|
||||
options.video.v_sync = stringToBool(value);
|
||||
video.v_sync = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de audio
|
||||
else if (var == "audio.enabled")
|
||||
{
|
||||
options.audio.enabled = stringToBool(value);
|
||||
audio.enabled = stringToBool(value);
|
||||
}
|
||||
else if (var == "audio.volume")
|
||||
{
|
||||
options.audio.volume = std::clamp(std::stoi(value), 0, 100);
|
||||
audio.volume = std::clamp(std::stoi(value), 0, 100);
|
||||
}
|
||||
else if (var == "audio.music.enabled")
|
||||
{
|
||||
options.audio.music.enabled = stringToBool(value);
|
||||
audio.music.enabled = stringToBool(value);
|
||||
}
|
||||
else if (var == "audio.music.volume")
|
||||
{
|
||||
options.audio.music.volume = std::clamp(std::stoi(value), 0, 100);
|
||||
audio.music.volume = std::clamp(std::stoi(value), 0, 100);
|
||||
}
|
||||
else if (var == "audio.sound.enabled")
|
||||
{
|
||||
options.audio.sound.enabled = stringToBool(value);
|
||||
audio.sound.enabled = stringToBool(value);
|
||||
}
|
||||
else if (var == "audio.sound.volume")
|
||||
{
|
||||
options.audio.sound.volume = std::clamp(std::stoi(value), 0, 100);
|
||||
audio.sound.volume = std::clamp(std::stoi(value), 0, 100);
|
||||
}
|
||||
|
||||
// Opciones de juego
|
||||
else if (var == "game.language")
|
||||
{
|
||||
options.game.language = static_cast<lang::Code>(std::stoi(value));
|
||||
options.pending_changes.new_language = options.game.language;
|
||||
game.language = static_cast<Lang::Code>(std::stoi(value));
|
||||
pending_changes.new_language = game.language;
|
||||
}
|
||||
else if (var == "game.difficulty")
|
||||
{
|
||||
options.game.difficulty = static_cast<GameDifficulty>(std::stoi(value));
|
||||
options.pending_changes.new_difficulty = options.game.difficulty;
|
||||
game.difficulty = static_cast<DifficultyCode>(std::stoi(value));
|
||||
pending_changes.new_difficulty = game.difficulty;
|
||||
}
|
||||
else if (var == "game.autofire")
|
||||
{
|
||||
options.game.autofire = stringToBool(value);
|
||||
game.autofire = stringToBool(value);
|
||||
}
|
||||
else if (var == "game.shutdown_enabled")
|
||||
{
|
||||
options.game.shutdown_enabled = stringToBool(value);
|
||||
game.shutdown_enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
// Opciones de mandos
|
||||
else if (var == "controller.0.name")
|
||||
{
|
||||
options.controllers.at(0).name = value;
|
||||
controllers.at(0).name = value;
|
||||
}
|
||||
else if (var == "controller.0.player")
|
||||
{
|
||||
options.controllers.at(0).player_id = std::clamp(std::stoi(value), 1, 2);
|
||||
controllers.at(0).player_id = std::clamp(std::stoi(value), 1, 2);
|
||||
}
|
||||
else if (var == "controller.0.type")
|
||||
{
|
||||
options.controllers.at(0).type = static_cast<InputDeviceToUse>(std::stoi(value));
|
||||
controllers.at(0).type = static_cast<InputDeviceToUse>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.0.button.fire_left")
|
||||
{
|
||||
options.controllers.at(0).buttons.at(0) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
controllers.at(0).buttons.at(0) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.0.button.fire_center")
|
||||
{
|
||||
options.controllers.at(0).buttons.at(1) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
controllers.at(0).buttons.at(1) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.0.button.fire_right")
|
||||
{
|
||||
options.controllers.at(0).buttons.at(2) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
controllers.at(0).buttons.at(2) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.0.button.start")
|
||||
{
|
||||
options.controllers.at(0).buttons.at(3) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
controllers.at(0).buttons.at(3) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.0.button.service")
|
||||
{
|
||||
options.controllers.at(0).buttons.at(4) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
controllers.at(0).buttons.at(4) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.1.name")
|
||||
{
|
||||
options.controllers.at(1).name = value;
|
||||
controllers.at(1).name = value;
|
||||
}
|
||||
else if (var == "controller.1.player")
|
||||
{
|
||||
options.controllers.at(1).player_id = std::clamp(std::stoi(value), 1, 2);
|
||||
controllers.at(1).player_id = std::clamp(std::stoi(value), 1, 2);
|
||||
}
|
||||
else if (var == "controller.1.type")
|
||||
{
|
||||
options.controllers.at(1).type = static_cast<InputDeviceToUse>(std::stoi(value));
|
||||
controllers.at(1).type = static_cast<InputDeviceToUse>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.1.button.fire_left")
|
||||
{
|
||||
options.controllers.at(1).buttons.at(0) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
controllers.at(1).buttons.at(0) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.1.button.fire_center")
|
||||
{
|
||||
options.controllers.at(1).buttons.at(1) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
controllers.at(1).buttons.at(1) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.1.button.fire_right")
|
||||
{
|
||||
options.controllers.at(1).buttons.at(2) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
controllers.at(1).buttons.at(2) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.1.button.start")
|
||||
{
|
||||
options.controllers.at(1).buttons.at(3) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
controllers.at(1).buttons.at(3) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
}
|
||||
else if (var == "controller.1.button.service")
|
||||
{
|
||||
options.controllers.at(1).buttons.at(4) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
controllers.at(1).buttons.at(4) = static_cast<SDL_GamepadButton>(std::stoi(value));
|
||||
}
|
||||
|
||||
// Lineas vacias o que empiezan por comentario
|
||||
@@ -343,7 +348,7 @@ bool setOptions(const std::string &var, const std::string &value)
|
||||
// Asigna el teclado al jugador
|
||||
void setKeyboardToPlayer(int player_id)
|
||||
{
|
||||
for (auto &controller : options.controllers)
|
||||
for (auto &controller : controllers)
|
||||
{
|
||||
if (controller.player_id == player_id)
|
||||
{
|
||||
@@ -359,20 +364,20 @@ void setKeyboardToPlayer(int player_id)
|
||||
// Intercambia el teclado de jugador
|
||||
void swapOptionsKeyboard()
|
||||
{
|
||||
std::swap(options.controllers.at(0).type, options.controllers.at(1).type);
|
||||
std::swap(controllers.at(0).type, controllers.at(1).type);
|
||||
}
|
||||
|
||||
// Intercambia los jugadores asignados a los dos primeros mandos
|
||||
void swapOptionsControllers()
|
||||
{
|
||||
std::swap(options.controllers.at(0).player_id, options.controllers.at(1).player_id);
|
||||
std::swap(options.controllers.at(0).type, options.controllers.at(1).type);
|
||||
std::swap(controllers.at(0).player_id, controllers.at(1).player_id);
|
||||
std::swap(controllers.at(0).type, controllers.at(1).type);
|
||||
}
|
||||
|
||||
// Averigua quien está usando el teclado
|
||||
int getPlayerWhoUsesKeyboard()
|
||||
{
|
||||
for (const auto &controller : options.controllers)
|
||||
for (const auto &controller : controllers)
|
||||
{
|
||||
if (controller.type == InputDeviceToUse::ANY)
|
||||
{
|
||||
@@ -385,10 +390,24 @@ int getPlayerWhoUsesKeyboard()
|
||||
// Aplica los cambios pendientes copiando los valores a sus variables
|
||||
void applyPendingChanges()
|
||||
{
|
||||
if (options.pending_changes.has_pending_changes)
|
||||
if (pending_changes.has_pending_changes)
|
||||
{
|
||||
options.game.language = options.pending_changes.new_language;
|
||||
options.game.difficulty = options.pending_changes.new_difficulty;
|
||||
options.pending_changes.has_pending_changes = false;
|
||||
game.language = pending_changes.new_language;
|
||||
game.difficulty = pending_changes.new_difficulty;
|
||||
pending_changes.has_pending_changes = false;
|
||||
}
|
||||
}
|
||||
|
||||
void checkPendingChanges()
|
||||
{
|
||||
if (game.language != pending_changes.new_language ||
|
||||
game.difficulty != pending_changes.new_difficulty)
|
||||
{
|
||||
pending_changes.has_pending_changes = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
pending_changes.has_pending_changes = false;
|
||||
}
|
||||
}
|
||||
} // namespace Options
|
||||
Reference in New Issue
Block a user