forked from jaildesigner-jailgames/jaildoctors_dilemma
linter
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
#include "game/gameplay/cheevos.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stddef.h> // Para NULL
|
||||
|
||||
#include <cstddef> // Para NULL
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_ofstream
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include <utility>
|
||||
|
||||
#include "game/options.hpp" // Para Options, options
|
||||
#include "game/ui/notifier.hpp" // Para Notifier
|
||||
#include "game/options.hpp" // Para Options, options
|
||||
#include "game/ui/notifier.hpp" // Para Notifier
|
||||
|
||||
// [SINGLETON]
|
||||
Cheevos* Cheevos::cheevos = nullptr;
|
||||
@@ -23,13 +24,13 @@ void Cheevos::destroy() {
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
Cheevos* Cheevos::get() {
|
||||
auto Cheevos::get() -> Cheevos* {
|
||||
return Cheevos::cheevos;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Cheevos::Cheevos(const std::string& file)
|
||||
: file_(file) {
|
||||
Cheevos::Cheevos(std::string file)
|
||||
: file_(std::move(file)) {
|
||||
init();
|
||||
loadFromFile();
|
||||
}
|
||||
@@ -57,7 +58,7 @@ void Cheevos::init() {
|
||||
}
|
||||
|
||||
// Busca un logro por id y devuelve el indice
|
||||
int Cheevos::find(int id) {
|
||||
auto Cheevos::find(int id) -> int {
|
||||
for (int i = 0; i < (int)cheevos_list_.size(); ++i) {
|
||||
if (cheevos_list_[i].id == id) {
|
||||
return i;
|
||||
@@ -103,7 +104,7 @@ void Cheevos::loadFromFile() {
|
||||
// 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..." << '\n';
|
||||
}
|
||||
|
||||
// Crea el fichero en modo escritura (binario)
|
||||
@@ -111,7 +112,7 @@ void Cheevos::loadFromFile() {
|
||||
|
||||
if (new_file) {
|
||||
if (Options::console) {
|
||||
std::cout << "New " << file_ << " created!" << std::endl;
|
||||
std::cout << "New " << file_ << " created!" << '\n';
|
||||
}
|
||||
|
||||
// Guarda la información
|
||||
@@ -120,14 +121,14 @@ void Cheevos::loadFromFile() {
|
||||
}
|
||||
} else {
|
||||
if (Options::console) {
|
||||
std::cerr << "Error: Unable to create " << file_ << "!" << std::endl;
|
||||
std::cerr << "Error: Unable to create " << file_ << "!" << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
// El fichero existe
|
||||
else {
|
||||
if (Options::console) {
|
||||
std::cout << "Reading " << file_ << std::endl;
|
||||
std::cout << "Reading " << file_ << '\n';
|
||||
}
|
||||
|
||||
// Carga los datos
|
||||
@@ -143,21 +144,21 @@ void Cheevos::saveToFile() {
|
||||
SDL_IOStream* file = SDL_IOFromFile(this->file_.c_str(), "w+b");
|
||||
if (file != nullptr) {
|
||||
// Guarda la información
|
||||
for (int i = 0; i < (int)cheevos_list_.size(); ++i) {
|
||||
SDL_WriteIO(file, &cheevos_list_[i].completed, sizeof(bool));
|
||||
for (auto& i : cheevos_list_) {
|
||||
SDL_WriteIO(file, &i.completed, sizeof(bool));
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
SDL_CloseIO(file);
|
||||
} else {
|
||||
if (Options::console) {
|
||||
std::cout << "Error: Unable to save file! " << SDL_GetError() << std::endl;
|
||||
std::cout << "Error: Unable to save file! " << SDL_GetError() << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Devuelve el número total de logros desbloqueados
|
||||
int Cheevos::getTotalUnlockedAchievements() {
|
||||
auto Cheevos::getTotalUnlockedAchievements() -> int {
|
||||
int count = 0;
|
||||
for (const auto& cheevo : cheevos_list_) {
|
||||
if (cheevo.completed) {
|
||||
|
||||
Reference in New Issue
Block a user