Arreglada la cárrega de opcions i recursos

Modificats els parametros dels fitxers .ani a snake_case
This commit is contained in:
2025-02-26 08:50:12 +01:00
parent a07a08adb7
commit a8e5517a77
67 changed files with 244 additions and 217 deletions

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=8
frame_width=8
frame_height=8
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=16
frame_width=8
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=8
frame_width=8
frame_height=8
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=9
frameHeight=7
frame_width=9
frame_height=7
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=16
frame_width=8
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=8
frame_width=16
frame_height=8
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=24
frameHeight=32
frame_width=24
frame_height=32
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=10
frameHeight=16
frame_width=10
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=16
frame_width=8
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=16
frame_width=8
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=22
frameHeight=16
frame_width=22
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=7
frameHeight=7
frame_width=7
frame_height=7
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=13
frameHeight=15
frame_width=13
frame_height=15
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=11
frameHeight=13
frame_width=11
frame_height=13
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=16
frame_width=8
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=16
frame_width=8
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=32
frame_width=16
frame_height=32
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=8
frame_width=8
frame_height=8
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=16
frame_width=8
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=43
frameHeight=44
frame_width=43
frame_height=44
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=79
frameHeight=90
frame_width=79
frame_height=90
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=62
frameHeight=47
frame_width=62
frame_height=47
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=64
frameHeight=64
frame_width=64
frame_height=64
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=8
frame_width=8
frame_height=8
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=7
frameHeight=8
frame_width=7
frame_height=8
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=16
frame_width=16
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=18
frame_width=16
frame_height=18
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=24
frameHeight=16
frame_width=24
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=16
frame_width=8
frame_height=16
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=5
frameHeight=8
frame_width=5
frame_height=8
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=8
frame_width=8
frame_height=8
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=16
frameHeight=32
frame_width=16
frame_height=32
[animation]
name=default

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=16
frame_width=8
frame_height=16
[animation]
name=stand

View File

@@ -1,5 +1,5 @@
frameWidth=8
frameHeight=16
frame_width=8
frame_height=16
[animation]
name=stand

View File

@@ -1,5 +1,5 @@
frameWidth=19
frameHeight=18
frame_width=19
frame_height=18
[animation]
name=default

View File

@@ -108,24 +108,24 @@ void Cheevos::invalidate(int id)
// Carga el estado de los logros desde un fichero
void Cheevos::loadFromFile()
{
std::ifstream file(this->file_, std::ios::binary);
std::ifstream file(file_, std::ios::binary);
// El fichero no existe
if (!file)
{
if (options.console)
{
std::cout << "Warning: Unable to open file! Creating new file..." << std::endl;
std::cout << "Warning: Unable to open " << file_ << "! Creating new file..." << std::endl;
}
// Crea el fichero en modo escritura (binario)
std::ofstream newFile(this->file_, std::ios::binary);
std::ofstream newFile(file_, std::ios::binary);
if (newFile)
{
if (options.console)
{
std::cout << "New file created!" << std::endl;
std::cout << "New " << file_ << " created!" << std::endl;
}
// Guarda la información
@@ -138,7 +138,7 @@ void Cheevos::loadFromFile()
{
if (options.console)
{
std::cerr << "Error: Unable to create file!" << std::endl;
std::cerr << "Error: Unable to create " << file_ << "!" << std::endl;
}
}
}
@@ -147,7 +147,7 @@ void Cheevos::loadFromFile()
{
if (options.console)
{
std::cout << "Reading file...!" << std::endl;
std::cout << "Reading " << file_ << std::endl;
}
// Carga los datos

View File

@@ -321,7 +321,7 @@ bool Director::initSDL()
const auto window_width = options.video.border.enabled ? options.game.width + options.video.border.width * 2 : options.game.width;
const auto window_height = options.video.border.enabled ? options.game.height + options.video.border.height * 2 : options.game.height;
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width, window_height, SDL_WINDOW_HIDDEN);
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width * options.window.zoom, window_height * options.window.zoom, SDL_WINDOW_HIDDEN);
if (window_ == nullptr)
{
if (options.console)

View File

@@ -5,6 +5,9 @@
#include <iostream> // for cout, cerr
#include <unordered_map> // for unordered_map, operator==, _Node_const_i...
#include <utility> // for pair
#include <sstream>
#include <string>
#include <algorithm>
// Variables
Options options;
@@ -42,25 +45,35 @@ bool loadOptionsFromFile(const std::string &file_path)
// Si el fichero se puede abrir
if (file.good())
{
// Procesa el fichero linea a linea
// Procesa el fichero línea a línea
if (options.console)
{
std::cout << "Reading file config.txt\n";
}
while (std::getline(file, line))
{
// Comprueba que la linea no sea un comentario
if (line.substr(0, 1) != "#")
// Elimina espacios en blanco iniciales y finales
line = std::string(std::find_if(line.begin(), line.end(), [](int ch) { return !std::isspace(ch); }), line.end());
line.erase(std::find_if(line.rbegin(), line.rend(), [](int ch) { return !std::isspace(ch); }).base(), line.end());
// Ignora líneas vacías o comentarios
if (line.empty() || line[0] == '#')
{
// Encuentra la posición del caracter '='
int pos = line.find("=");
// Procesa las dos subcadenas
if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length())))
continue;
}
// Usa un stringstream para dividir la línea en dos partes
std::istringstream iss(line);
std::string key, value;
if (iss >> key >> value)
{
if (!setOptions(key, value))
{
if (options.console)
{
std::cout << "Warning: file config.txt\n";
std::cout << "unknown parameter " << line.substr(0, pos).c_str() << std::endl;
std::cout << "unknown parameter " << key << std::endl;
}
success = false;
}
@@ -74,8 +87,6 @@ bool loadOptionsFromFile(const std::string &file_path)
}
file.close();
}
// El fichero no existe
else
{
// Crea el fichero con los valores por defecto
@@ -87,19 +98,16 @@ bool loadOptionsFromFile(const std::string &file_path)
{
initOptions();
saveOptionsToFile(file_path);
}
// Normaliza los valores
if (options.video.mode != 0 &&
options.video.mode != SDL_WINDOW_FULLSCREEN &&
options.video.mode != SDL_WINDOW_FULLSCREEN_DESKTOP)
if (options.console)
{
options.video.mode = 0;
std::cout << "Wrong config file: initializing options.\n\n";
}
}
return success;
}
// Guarda las opciones en un fichero
bool saveOptionsToFile(const std::string &file_path)
{
@@ -122,25 +130,38 @@ bool saveOptionsToFile(const std::string &file_path)
}
// Escribe en el fichero
file << "version=" << options.version << "\n";
file << "# Versión de la configuración\n";
file << "version " << options.version << "\n";
file << "\n## CONTROL\n";
file << "keys=" << static_cast<int>(options.keys) << "\n";
file << "# Esquema de control: 0 = Cursores, 1 = OPQ, 2 = WAD\n";
file << "keys " << static_cast<int>(options.keys) << "\n";
file << "\n## WINDOW\n";
file << "window.zoom=" << options.window.zoom << "\n";
file << "# Zoom de la ventana: 1 = Normal, 2 = Doble, 3 = Triple, ...\n";
file << "window.zoom " << options.window.zoom << "\n";
file << "\n## VIDEO\n";
file << "video.mode=" << options.video.mode << "\n";
file << "video.filter=" << static_cast<int>(options.video.filter) << "\n";
file << "video.shaders=" << boolToString(options.video.shaders) << "\n";
file << "video.vertical_sync=" << boolToString(options.video.vertical_sync) << "\n";
file << "video.integer_scale=" << boolToString(options.video.integer_scale) << "\n";
file << "video.keep_aspect=" << boolToString(options.video.keep_aspect) << "\n";
file << "video.border.enabled=" << boolToString(options.video.border.enabled) << "\n";
file << "video.border.width=" << options.video.border.width << "\n";
file << "video.border.height=" << options.video.border.height << "\n";
file << "video.palette=" << static_cast<int>(options.video.palette) << "\n";
file << "# Modo de video: 0 = Ventana, 1 = Pantalla completa, 2 = Pantalla completa (escritorio)\n";
file << "video.mode " << options.video.mode << "\n";
file << "# Filtro de pantalla: 0 = Nearest, 1 = Linear\n";
file << "video.filter " << static_cast<int>(options.video.filter) << "\n";
file << "# Shaders: 1 = Activado, 0 = Desactivado\n";
file << "video.shaders " << boolToString(options.video.shaders) << "\n";
file << "# Sincronización vertical: 1 = Activado, 0 = Desactivado\n";
file << "video.vertical_sync " << boolToString(options.video.vertical_sync) << "\n";
file << "# Escalado entero: 1 = Activado, 0 = Desactivado\n";
file << "video.integer_scale " << boolToString(options.video.integer_scale) << "\n";
file << "# Mantener aspecto: 1 = Activado, 0 = Desactivado\n";
file << "video.keep_aspect " << boolToString(options.video.keep_aspect) << "\n";
file << "# Borde: 1 = Activado, 0 = Desactivado\n";
file << "video.border.enabled " << boolToString(options.video.border.enabled) << "\n";
file << "# Ancho del borde\n";
file << "video.border.width " << options.video.border.width << "\n";
file << "# Alto del borde\n";
file << "video.border.height " << options.video.border.height << "\n";
file << "# Paleta: 0 = ZX Spectrum, 1 = ZX Arne\n";
file << "video.palette " << static_cast<int>(options.video.palette) << "\n";
// Cierra el fichero
file.close();
@@ -156,10 +177,12 @@ bool setOptions(const std::string &var, const std::string &value)
{ options.version = v; }},
{"keys", [](std::string v)
{ options.keys = static_cast<ControlScheme>(safeStoi(v, static_cast<int>(ControlScheme::CURSOR))); }},
{"video.mode", [](std::string v)
{ options.video.mode = safeStoi(v, 0); }},
{"window.zoom", [](std::string v)
{ options.window.zoom = safeStoi(v, 1); }},
{"video.mode", [](std::string v)
{ options.video.mode = safeStoi(v, 0); }},
{"video.filter", [](std::string v)
{ options.video.filter = static_cast<ScreenFilter>(safeStoi(v, static_cast<int>(DEFAULT_VIDEO_FILTER))); }},
{"video.shaders", [](std::string v)
{ options.video.shaders = stringToBool(v); }},
{"video.vertical_sync", [](std::string v)

View File

@@ -72,7 +72,7 @@ constexpr NotificationPosition DEFAULT_NOTIFICATION_POSITION = NotificationPosit
constexpr bool DEFAULT_NOTIFICATION_SOUND = true; // Sonido de las notificaciones por defecto
const Color DEFAULT_NOTIFICATION_COLOR = Color(48, 48, 48); // Color de las notificaciones por defecto
constexpr bool DEFAULT_CONSOLE = false; // Consola desactivada por defecto
constexpr std::string DEFAULT_VERSION = "v1.09"; // Versión por defecto
constexpr std::string DEFAULT_VERSION = "1.09"; // Versión por defecto
// Estructura para las opciones de las notificaciones
struct OptionsNotification

View File

@@ -563,7 +563,7 @@ void Player::move()
setState(s_standing);
#ifdef DEBUG
debugColor = {255, 255, 0};
debugPoint = {(int)x + (w / 2), p};
debugPoint = {(int)x_ + (w_ / 2), p};
#endif
}
else
@@ -631,7 +631,7 @@ void Player::playJumpSound()
}
#ifdef DEBUG
debug_->add("JUMP: " + std::to_string(jumpCounter / 4));
debug_->add("JUMP: " + std::to_string(jumping_counter_ / 4));
#endif
}
@@ -644,7 +644,7 @@ void Player::playFallSound()
}
#ifdef DEBUG
debug_->add("FALL: " + std::to_string(fallCounter / 4));
debug_->add("FALL: " + std::to_string(falling_counter_ / 4));
#endif
}

View File

@@ -57,6 +57,8 @@ void Resource::load()
loadTextures();
loadTextFiles();
loadAnimations();
loadTileMaps();
loadRooms();
createText();
std::cout << "\n** RESOURCES LOADED" << std::endl;
}
@@ -277,6 +279,7 @@ void Resource::loadTileMaps()
{
auto name = getFileName(l);
tile_maps_.emplace_back(ResourceTileMap(name, loadRoomTileFile(l)));
printWithDots("TileMap : ", name, "[ LOADED ]");
}
}
@@ -291,6 +294,7 @@ void Resource::loadRooms()
{
auto name = getFileName(l);
rooms_.emplace_back(ResourceRoom(name, std::make_shared<room_t>(loadRoomFile(l))));
printWithDots("Room : ", name, "[ LOADED ]");
}
}