ajustant el jugador
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#include <algorithm> // Para find, transform
|
||||
#include <cctype> // Para tolower
|
||||
#include <algorithm> // Para find, transform, ranges::all_of
|
||||
#include <array> // Para array
|
||||
#include <cctype> // Para tolower, isdigit
|
||||
#include <cmath> // Para round, abs
|
||||
#include <cstdlib> // Para abs
|
||||
#include <exception> // Para exception
|
||||
@@ -366,10 +367,36 @@ auto stringToColor(const std::string& str) -> Uint8 {
|
||||
auto it = PALETTE_MAP.find(str);
|
||||
if (it != PALETTE_MAP.end()) {
|
||||
return it->second;
|
||||
} // Si no se encuentra el color, devolvemos negro por defecto
|
||||
}
|
||||
|
||||
// Fallback: si el string es numérico (p.ej. "4"), lo tratamos como índice de paleta
|
||||
if (!str.empty() && std::ranges::all_of(str, [](char c) { return std::isdigit(static_cast<unsigned char>(c)) != 0; })) {
|
||||
const int IDX = safeStoi(str, 0);
|
||||
if (IDX >= 0 && IDX <= 255) {
|
||||
return static_cast<Uint8>(IDX);
|
||||
}
|
||||
}
|
||||
|
||||
// Si no se encuentra el color, devolvemos negro por defecto
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Inverso de stringToColor: devuelve el nombre canónico para un índice de paleta (o el propio número si no hay)
|
||||
auto colorToString(Uint8 index) -> std::string {
|
||||
static const std::array<const char*, 16> NAMES = {
|
||||
"black", "bright_black",
|
||||
"blue", "bright_blue",
|
||||
"red", "bright_red",
|
||||
"magenta", "bright_magenta",
|
||||
"green", "bright_green",
|
||||
"cyan", "bright_cyan",
|
||||
"yellow", "bright_yellow",
|
||||
"white", "bright_white"};
|
||||
if (index < NAMES.size()) { return NAMES[index]; }
|
||||
if (index == 255) { return "transparent"; }
|
||||
return std::to_string(index);
|
||||
}
|
||||
|
||||
// Convierte una cadena a un entero de forma segura
|
||||
auto safeStoi(const std::string& value, int default_value) -> int {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user