forked from jaildesigner-jailgames/jaildoctors_dilemma
Reestructurant la classe Options
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include "utils.h"
|
||||
#include <filesystem> // Para path
|
||||
#include <stdlib.h> // Para free, malloc, abs
|
||||
#include <cmath> // Para round, abs
|
||||
#include <filesystem> // Para path
|
||||
#include <stdlib.h> // Para free, malloc, abs
|
||||
#include <cmath> // Para round, abs
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
|
||||
// Calcula el cuadrado de la distancia entre dos puntos
|
||||
double distanceSquared(int x1, int y1, int x2, int y2)
|
||||
@@ -12,7 +14,7 @@ double distanceSquared(int x1, int y1, int x2, int y2)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre dos circulos
|
||||
bool checkCollision(circle_t &a, circle_t &b)
|
||||
bool checkCollision(Circle &a, Circle &b)
|
||||
{
|
||||
// Calcula el radio total al cuadrado
|
||||
int totalRadiusSquared = a.r + b.r;
|
||||
@@ -30,7 +32,7 @@ bool checkCollision(circle_t &a, circle_t &b)
|
||||
}
|
||||
|
||||
// Detector de colisiones entre un circulo y un rectangulo
|
||||
bool checkCollision(circle_t &a, SDL_Rect &b)
|
||||
bool checkCollision(Circle &a, SDL_Rect &b)
|
||||
{
|
||||
// Closest point on collision box
|
||||
int cX, cY;
|
||||
@@ -350,9 +352,9 @@ bool checkCollision(SDL_Point &p, d_line_t &l)
|
||||
}
|
||||
|
||||
// Devuelve un color_t a partir de un string
|
||||
color_t stringToColor(palette_e pal, std::string str)
|
||||
Color stringToColor(Palette pal, std::string str)
|
||||
{
|
||||
if (pal == p_zxspectrum)
|
||||
if (pal == Palette::ZXSPECTRUM)
|
||||
{
|
||||
if (str == "black")
|
||||
{
|
||||
@@ -435,8 +437,8 @@ color_t stringToColor(palette_e pal, std::string str)
|
||||
}
|
||||
}
|
||||
|
||||
else if (pal == p_zxarne)
|
||||
{ // zxarne
|
||||
else if (pal == Palette::ZXARNE)
|
||||
{
|
||||
if (str == "black")
|
||||
{
|
||||
return {0x00, 0x00, 0x00};
|
||||
@@ -521,34 +523,35 @@ color_t stringToColor(palette_e pal, std::string str)
|
||||
return {0x00, 0x00, 0x00};
|
||||
}
|
||||
|
||||
// Convierte una cadena en un valor booleano
|
||||
bool stringToBool(std::string str)
|
||||
// Convierte una cadena a un entero de forma segura
|
||||
int safeStoi(const std::string &value, int defaultValue)
|
||||
{
|
||||
if (str == "true")
|
||||
try
|
||||
{
|
||||
return true;
|
||||
return std::stoi(value);
|
||||
}
|
||||
else
|
||||
catch (const std::exception &)
|
||||
{
|
||||
return false;
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Convierte un valor booleano en una cadena
|
||||
// Convierte una cadena a un booleano
|
||||
bool stringToBool(const std::string &str)
|
||||
{
|
||||
std::string lowerStr = str;
|
||||
std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), ::tolower);
|
||||
return (lowerStr == "true" || lowerStr == "1" || lowerStr == "yes" || lowerStr == "on");
|
||||
}
|
||||
|
||||
// Convierte un booleano a una cadena
|
||||
std::string boolToString(bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
return "true";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "false";
|
||||
}
|
||||
return value ? "1" : "0";
|
||||
}
|
||||
|
||||
// Compara dos colores
|
||||
bool colorAreEqual(color_t color1, color_t color2)
|
||||
bool colorAreEqual(Color color1, Color color2)
|
||||
{
|
||||
const bool r = color1.r == color2.r;
|
||||
const bool g = color1.g == color2.g;
|
||||
|
||||
Reference in New Issue
Block a user