Color: afegit static Color fromHex(const std::string& hexStr)

This commit is contained in:
2025-06-26 11:42:37 +02:00
parent 1ed09226e0
commit 78efcbccb7
6 changed files with 50 additions and 44 deletions

View File

@@ -31,9 +31,7 @@ title.arcade_edition_position 123
title.title_c_c_position 80
## BACKGROUND
background.attenuate_color.r 255
background.attenuate_color.g 255
background.attenuate_color.b 255
background.attenuate_color FFFFFF
background.attenuate_alpha 0
## BALLOONS
@@ -50,6 +48,4 @@ balloon_4.grav 0.10f
notification.pos_v TOP
notification.pos_h LEFT
notification.sound false
notification.color.r 48
notification.color.g 48
notification.color.b 48
notification.color 303030

View File

@@ -31,9 +31,7 @@ title.arcade_edition_position 123
title.title_c_c_position 80
## BACKGROUND
background.attenuate_color.r 255
background.attenuate_color.g 255
background.attenuate_color.b 255
background.attenuate_color FFFFFF
background.attenuate_alpha 0
## BALLOONS
@@ -50,6 +48,4 @@ balloon_4.grav 0.10f
notification.pos_v TOP
notification.pos_h LEFT
notification.sound false
notification.color.r 48
notification.color.g 48
notification.color.b 48
notification.color 303030

View File

@@ -142,6 +142,9 @@ void Director::loadParams()
void Director::loadScoreFile()
{
auto manager = std::make_unique<ManageHiScoreTable>(Options::settings.hi_score_table);
#ifdef DEBUG
manager->clear();
#else
if (overrides.clear_hi_score_table)
{
manager->clear();
@@ -150,6 +153,7 @@ void Director::loadScoreFile()
{
manager->loadFromFile(Asset::get()->get("score.bin"));
}
#endif
}
// Asigna los botones y teclas al objeto Input

View File

@@ -5,7 +5,7 @@
#include "utils.h" // Archivo de utilidades
// Tamaño máximo del nombre
constexpr size_t NAME_SIZE = 3;
constexpr size_t NAME_SIZE = 5;
// Clase EnterName
class EnterName
@@ -32,9 +32,9 @@ private:
std::string name_; // Nombre en proceso
size_t position_ = 0; // Índice del carácter que se edita
bool position_overflow_ = false; // Flag para exceder límite
std::array<int, NAME_SIZE> character_index_; // Índices a `character_list_`
std::array<int, NAME_SIZE> character_index_; // Índices a "character_list_"
void updateNameFromCharacterIndex(); // Actualiza `name_` según `character_index_`
void updateNameFromCharacterIndex(); // Actualiza "name_" según "character_index_"
void initCharacterIndex(const std::string &name); // Inicializa índices desde el nombre
int findIndex(char character) const; // Busca el índice de un carácter en `character_list_`
int findIndex(char character) const; // Busca el índice de un carácter en "character_list_"
};

View File

@@ -240,19 +240,9 @@ bool setParams(const std::string &var, const std::string &value)
}
// BACKGROUND
else if (var == "background.attenuate_color.r")
else if (var == "background.attenuate_color")
{
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);
param.background.attenuate_color = Color::fromHex(value);
}
else if (var == "background.attenuate_alpha")
@@ -328,19 +318,9 @@ bool setParams(const std::string &var, const std::string &value)
param.notification.sound = stringToBool(value);
}
else if (var == "notification.color.r")
else if (var == "notification.color")
{
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);
param.notification.color = Color::fromHex(value);
}
// RESTO

View File

@@ -8,6 +8,7 @@
#include <string> // Para string
#include <vector> // Para vector
#include <array> // Para array
#include <stdexcept>
// --- Constantes ---
constexpr int BLOCK = 8;
@@ -19,10 +20,9 @@ struct Overrides
{
std::string param_file; // Fichero de parametros a utilizar
bool clear_hi_score_table; // Reinicia la tabla de records
bool set_v_sync; // Establece el vsync
Overrides()
: param_file(""), clear_hi_score_table(false), set_v_sync(false) {}
: param_file(""), clear_hi_score_table(false) {}
};
extern Overrides overrides;
@@ -57,6 +57,36 @@ struct Color
std::max(0, g - amount),
std::max(0, b - amount));
}
// Método estático para crear Color desde string hexadecimal
static Color fromHex(const std::string& hexStr)
{
std::string hex = hexStr;
// Quitar '#' si existe
if (!hex.empty() && hex[0] == '#') {
hex = hex.substr(1);
}
// Verificar longitud válida (6 caracteres para RGB)
if (hex.length() != 6) {
throw std::invalid_argument("String hexadecimal debe tener 6 caracteres");
}
// Verificar que todos los caracteres sean hexadecimales válidos
for (char c : hex) {
if (!std::isxdigit(c)) {
throw std::invalid_argument("String contiene caracteres no hexadecimales");
}
}
// Convertir cada par de caracteres a valores RGB
Uint8 r = static_cast<Uint8>(std::stoi(hex.substr(0, 2), nullptr, 16));
Uint8 g = static_cast<Uint8>(std::stoi(hex.substr(2, 2), nullptr, 16));
Uint8 b = static_cast<Uint8>(std::stoi(hex.substr(4, 2), nullptr, 16));
return Color(r, g, b);
}
};
// Estructura para definir un color HSV