renombrades extensions .h a .hpp
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#include "manage_hiscore_table.h"
|
||||
#include "manage_hiscore_table.hpp"
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_ReadIO, SDL_WriteIO, SDL_CloseIO, SDL_GetError, SDL_IOFromFile, SDL_LogCategory, SDL_LogError, SDL_LogInfo
|
||||
|
||||
#include <algorithm> // Para find_if, sort
|
||||
#include <iterator> // Para distance
|
||||
|
||||
#include "utils.h" // Para getFileName
|
||||
#include "utils.hpp" // Para getFileName
|
||||
|
||||
// Resetea la tabla a los valores por defecto
|
||||
void ManageHiScoreTable::clear() {
|
||||
@@ -54,7 +54,7 @@ void ManageHiScoreTable::clear() {
|
||||
}
|
||||
|
||||
// Añade un elemento a la tabla
|
||||
auto ManageHiScoreTable::add(const HiScoreEntry &entry) -> int {
|
||||
auto ManageHiScoreTable::add(const HiScoreEntry& entry) -> int {
|
||||
// Añade la entrada a la tabla
|
||||
table_.push_back(entry);
|
||||
|
||||
@@ -62,7 +62,7 @@ auto ManageHiScoreTable::add(const HiScoreEntry &entry) -> int {
|
||||
sort();
|
||||
|
||||
// Encontrar la posición del nuevo elemento
|
||||
auto it = std::ranges::find_if(table_, [&](const HiScoreEntry &e) {
|
||||
auto it = std::ranges::find_if(table_, [&](const HiScoreEntry& e) {
|
||||
return e.name == entry.name && e.score == entry.score && e.one_credit_complete == entry.one_credit_complete;
|
||||
});
|
||||
|
||||
@@ -89,17 +89,17 @@ auto ManageHiScoreTable::add(const HiScoreEntry &entry) -> int {
|
||||
void ManageHiScoreTable::sort() {
|
||||
struct
|
||||
{
|
||||
auto operator()(const HiScoreEntry &a, const HiScoreEntry &b) const -> bool { return a.score > b.score; }
|
||||
auto operator()(const HiScoreEntry& a, const HiScoreEntry& b) const -> bool { return a.score > b.score; }
|
||||
} score_descending_comparator;
|
||||
|
||||
std::ranges::sort(table_, score_descending_comparator);
|
||||
}
|
||||
|
||||
// Carga la tabla desde un fichero
|
||||
auto ManageHiScoreTable::loadFromFile(const std::string &file_path) -> bool {
|
||||
auto ManageHiScoreTable::loadFromFile(const std::string& file_path) -> bool {
|
||||
clear();
|
||||
auto success = true;
|
||||
auto *file = SDL_IOFromFile(file_path.c_str(), "rb");
|
||||
auto* file = SDL_IOFromFile(file_path.c_str(), "rb");
|
||||
|
||||
if (file != nullptr) {
|
||||
table_.clear(); // Limpia la tabla actual
|
||||
@@ -143,9 +143,9 @@ auto ManageHiScoreTable::loadFromFile(const std::string &file_path) -> bool {
|
||||
}
|
||||
|
||||
// Guarda la tabla en un fichero
|
||||
auto ManageHiScoreTable::saveToFile(const std::string &file_path) -> bool {
|
||||
auto ManageHiScoreTable::saveToFile(const std::string& file_path) -> bool {
|
||||
auto success = true;
|
||||
auto *file = SDL_IOFromFile(file_path.c_str(), "w+b");
|
||||
auto* file = SDL_IOFromFile(file_path.c_str(), "w+b");
|
||||
|
||||
if (file != nullptr) {
|
||||
// Guarda el número de entradas en la tabla
|
||||
@@ -154,7 +154,7 @@ auto ManageHiScoreTable::saveToFile(const std::string &file_path) -> bool {
|
||||
|
||||
// Guarda los datos de cada entrada
|
||||
for (int i = 0; i < table_size; ++i) {
|
||||
const HiScoreEntry &entry = table_.at(i);
|
||||
const HiScoreEntry& entry = table_.at(i);
|
||||
|
||||
// Guarda la puntuación
|
||||
SDL_WriteIO(file, &entry.score, sizeof(int));
|
||||
|
||||
Reference in New Issue
Block a user