forked from jaildesigner-jailgames/jaildoctors_dilemma
De moment ja compila i executa, encara que no troba alguns fitxers
This commit is contained in:
237
source/utils.cpp
237
source/utils.cpp
@@ -1,10 +1,13 @@
|
||||
#include "utils.h"
|
||||
#include <filesystem> // Para path
|
||||
#include <stdlib.h> // Para free, malloc, abs
|
||||
#include <cmath> // Para round, abs
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <cctype>
|
||||
#include <stdlib.h> // for free, malloc, abs
|
||||
#include <algorithm> // for transform
|
||||
#include <cctype> // for tolower
|
||||
#include <cmath> // for round, abs
|
||||
#include <exception> // for exception
|
||||
#include <filesystem> // for path
|
||||
#include <iostream> // for basic_ostream, cout, basic_ios, ios, endl
|
||||
#include <unordered_map> // for unordered_map
|
||||
#include <string> // for string
|
||||
|
||||
// Calcula el cuadrado de la distancia entre dos puntos
|
||||
double distanceSquared(int x1, int y1, int x2, int y2)
|
||||
@@ -352,176 +355,74 @@ bool checkCollision(SDL_Point &p, d_line_t &l)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Devuelve un color_t a partir de un string
|
||||
Color stringToColor(Palette pal, std::string str)
|
||||
// Convierte una cadena a un color
|
||||
Color stringToColor(Palette pal, const std::string &str)
|
||||
{
|
||||
// Mapas de colores para cada paleta
|
||||
static const std::unordered_map<std::string, Color> zxSpectrumColors = {
|
||||
{"black", {0x00, 0x00, 0x00}},
|
||||
{"bright_black", {0x00, 0x00, 0x00}},
|
||||
{"blue", {0x00, 0x00, 0xD8}},
|
||||
{"bright_blue", {0x00, 0x00, 0xFF}},
|
||||
{"red", {0xD8, 0x00, 0x00}},
|
||||
{"bright_red", {0xFF, 0x00, 0x00}},
|
||||
{"magenta", {0xD8, 0x00, 0xD8}},
|
||||
{"bright_magenta", {0xFF, 0x00, 0xFF}},
|
||||
{"green", {0x00, 0xD8, 0x00}},
|
||||
{"bright_green", {0x00, 0xFF, 0x00}},
|
||||
{"cyan", {0x00, 0xD8, 0xD8}},
|
||||
{"bright_cyan", {0x00, 0xFF, 0xFF}},
|
||||
{"yellow", {0xD8, 0xD8, 0x00}},
|
||||
{"bright_yellow", {0xFF, 0xFF, 0x00}},
|
||||
{"white", {0xD8, 0xD8, 0xD8}},
|
||||
{"bright_white", {0xFF, 0xFF, 0xFF}}};
|
||||
|
||||
static const std::unordered_map<std::string, Color> zxArneColors = {
|
||||
{"black", {0x00, 0x00, 0x00}},
|
||||
{"bright_black", {0x3C, 0x35, 0x1F}},
|
||||
{"blue", {0x31, 0x33, 0x90}},
|
||||
{"bright_blue", {0x15, 0x59, 0xDB}},
|
||||
{"red", {0xA7, 0x32, 0x11}},
|
||||
{"bright_red", {0xD8, 0x55, 0x25}},
|
||||
{"magenta", {0xA1, 0x55, 0x89}},
|
||||
{"bright_magenta", {0xCD, 0x7A, 0x50}},
|
||||
{"green", {0x62, 0x9A, 0x31}},
|
||||
{"bright_green", {0x9C, 0xD3, 0x3C}},
|
||||
{"cyan", {0x28, 0xA4, 0xCB}},
|
||||
{"bright_cyan", {0x65, 0xDC, 0xD6}},
|
||||
{"yellow", {0xE8, 0xBC, 0x50}},
|
||||
{"bright_yellow", {0xF1, 0xE7, 0x82}},
|
||||
{"white", {0xBF, 0xBF, 0xBD}},
|
||||
{"bright_white", {0xF2, 0xF1, 0xED}}};
|
||||
|
||||
// Selecciona el mapa de colores adecuado según la paleta
|
||||
const std::unordered_map<std::string, Color> *paletteMap = nullptr;
|
||||
|
||||
if (pal == Palette::ZXSPECTRUM)
|
||||
{
|
||||
if (str == "black")
|
||||
{
|
||||
return {0x00, 0x00, 0x00};
|
||||
}
|
||||
|
||||
else if (str == "bright_black")
|
||||
{
|
||||
return {0x00, 0x00, 0x00};
|
||||
}
|
||||
|
||||
else if (str == "blue")
|
||||
{
|
||||
return {0x00, 0x00, 0xd8};
|
||||
}
|
||||
|
||||
else if (str == "bright_blue")
|
||||
{
|
||||
return {0x00, 0x00, 0xFF};
|
||||
}
|
||||
|
||||
else if (str == "red")
|
||||
{
|
||||
return {0xd8, 0x00, 0x00};
|
||||
}
|
||||
|
||||
else if (str == "bright_red")
|
||||
{
|
||||
return {0xFF, 0x00, 0x00};
|
||||
}
|
||||
|
||||
else if (str == "magenta")
|
||||
{
|
||||
return {0xd8, 0x00, 0xd8};
|
||||
}
|
||||
|
||||
else if (str == "bright_magenta")
|
||||
{
|
||||
return {0xFF, 0x00, 0xFF};
|
||||
}
|
||||
|
||||
else if (str == "green")
|
||||
{
|
||||
return {0x00, 0xd8, 0x00};
|
||||
}
|
||||
|
||||
else if (str == "bright_green")
|
||||
{
|
||||
return {0x00, 0xFF, 0x00};
|
||||
}
|
||||
|
||||
else if (str == "cyan")
|
||||
{
|
||||
return {0x00, 0xd8, 0xd8};
|
||||
}
|
||||
|
||||
else if (str == "bright_cyan")
|
||||
{
|
||||
return {0x00, 0xFF, 0xFF};
|
||||
}
|
||||
|
||||
else if (str == "yellow")
|
||||
{
|
||||
return {0xd8, 0xd8, 0x00};
|
||||
}
|
||||
|
||||
else if (str == "bright_yellow")
|
||||
{
|
||||
return {0xFF, 0xFF, 0x00};
|
||||
}
|
||||
|
||||
else if (str == "white")
|
||||
{
|
||||
return {0xd8, 0xd8, 0xd8};
|
||||
}
|
||||
|
||||
else if (str == "bright_white")
|
||||
{
|
||||
return {0xFF, 0xFF, 0xFF};
|
||||
}
|
||||
paletteMap = &zxSpectrumColors;
|
||||
}
|
||||
|
||||
else if (pal == Palette::ZXARNE)
|
||||
{
|
||||
if (str == "black")
|
||||
{
|
||||
return {0x00, 0x00, 0x00};
|
||||
}
|
||||
|
||||
else if (str == "bright_black")
|
||||
{
|
||||
return {0x3C, 0x35, 0x1F};
|
||||
}
|
||||
|
||||
else if (str == "blue")
|
||||
{
|
||||
return {0x31, 0x33, 0x90};
|
||||
}
|
||||
|
||||
else if (str == "bright_blue")
|
||||
{
|
||||
return {0x15, 0x59, 0xDB};
|
||||
}
|
||||
|
||||
else if (str == "red")
|
||||
{
|
||||
return {0xA7, 0x32, 0x11};
|
||||
}
|
||||
|
||||
else if (str == "bright_red")
|
||||
{
|
||||
return {0xD8, 0x55, 0x25};
|
||||
}
|
||||
|
||||
else if (str == "magenta")
|
||||
{
|
||||
return {0xA1, 0x55, 0x89};
|
||||
}
|
||||
|
||||
else if (str == "bright_magenta")
|
||||
{
|
||||
return {0xCD, 0x7A, 0x50};
|
||||
}
|
||||
|
||||
else if (str == "green")
|
||||
{
|
||||
return {0x62, 0x9A, 0x31};
|
||||
}
|
||||
|
||||
else if (str == "bright_green")
|
||||
{
|
||||
return {0x9C, 0xD3, 0x3C};
|
||||
}
|
||||
|
||||
else if (str == "cyan")
|
||||
{
|
||||
return {0x28, 0xA4, 0xCB};
|
||||
}
|
||||
|
||||
else if (str == "bright_cyan")
|
||||
{
|
||||
return {0x65, 0xDC, 0xD6};
|
||||
}
|
||||
|
||||
else if (str == "yellow")
|
||||
{
|
||||
return {0xE8, 0xBC, 0x50};
|
||||
}
|
||||
|
||||
else if (str == "bright_yellow")
|
||||
{
|
||||
return {0xF1, 0xE7, 0x82};
|
||||
}
|
||||
|
||||
else if (str == "white")
|
||||
{
|
||||
return {0xBF, 0xBF, 0xBD};
|
||||
}
|
||||
|
||||
else if (str == "bright_white")
|
||||
{
|
||||
return {0xF2, 0xF1, 0xED};
|
||||
}
|
||||
paletteMap = &zxArneColors;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Paleta desconocida, devolvemos negro por defecto
|
||||
return {0x00, 0x00, 0x00};
|
||||
}
|
||||
|
||||
return {0x00, 0x00, 0x00};
|
||||
// Busca el color en el mapa
|
||||
auto it = paletteMap->find(str);
|
||||
if (it != paletteMap->end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si no se encuentra el color, devolvemos negro por defecto
|
||||
return {0x00, 0x00, 0x00};
|
||||
}
|
||||
}
|
||||
|
||||
// Convierte una cadena a un entero de forma segura
|
||||
|
||||
Reference in New Issue
Block a user